From 5fca3c1071656991fefb555eb1800ffeb1783a48 Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Tue, 3 Nov 2026 22:54:55 +0800 Subject: [PATCH 1/4] feat: complete transaction utilities and governance builders --- CMakeLists.txt | 8 + doc/coverage/files.csv | 18 +- doc/coverage/functions.csv | 256 ++++----- doc/coverage/types.csv | 6 +- doc/src/coverage.rst | 9 +- .../sections/api/transaction_builder/fee.rst | 26 + .../api/transaction_builder/implicit_coin.rst | 11 + .../api/transaction_builder/index.rst | 5 + .../transaction_builder/script_data_hash.rst | 6 + .../transaction_balance_request.rst | 7 + .../transaction_balancing.rst | 14 + .../api/transaction_builder/usage.rst | 42 ++ lib/include/Cometa/Cometa.h | 6 + .../ProtocolParams/ProtocolParameters.h | 3 + .../Balancing/ImplicitCoin.h | 77 +++ .../Balancing/TransactionBalanceRequest.h | 97 ++++ .../Balancing/TransactionBalancing.h | 94 +++ lib/include/Cometa/TransactionBuilder/Fee.h | 147 +++++ .../TransactionBuilder/ScriptDataHash.h | 48 ++ .../SubTransactionBuilder.h | 126 ++++ .../TransactionBuilder/TransactionBuilder.h | 90 +++ .../Balancing/ImplicitCoin.cpp | 62 ++ .../Balancing/TransactionBalanceRequest.cpp | 45 ++ .../Balancing/TransactionBalancing.cpp | 241 ++++++++ lib/src/TransactionBuilder/Fee.cpp | 196 +++++++ lib/src/TransactionBuilder/ScriptDataHash.cpp | 60 ++ .../SubTransactionBuilder.cpp | 169 ++++++ .../TransactionBuilder/TransactionBuilder.cpp | 124 ++++ .../TransactionUtilityAccess.cpp | 90 +++ .../TransactionUtilityAccess.h | 77 +++ .../GovernanceBuilderTest.cpp | 167 ++++++ .../TransactionUtilitiesTest.cpp | 542 ++++++++++++++++++ lib/tests/installed/PackageTest.cpp | 14 + 33 files changed, 2738 insertions(+), 145 deletions(-) create mode 100644 doc/src/sections/api/transaction_builder/fee.rst create mode 100644 doc/src/sections/api/transaction_builder/implicit_coin.rst create mode 100644 doc/src/sections/api/transaction_builder/script_data_hash.rst create mode 100644 doc/src/sections/api/transaction_builder/transaction_balance_request.rst create mode 100644 doc/src/sections/api/transaction_builder/transaction_balancing.rst create mode 100644 lib/include/Cometa/TransactionBuilder/Balancing/ImplicitCoin.h create mode 100644 lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalanceRequest.h create mode 100644 lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalancing.h create mode 100644 lib/include/Cometa/TransactionBuilder/Fee.h create mode 100644 lib/include/Cometa/TransactionBuilder/ScriptDataHash.h create mode 100644 lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp create mode 100644 lib/src/TransactionBuilder/Balancing/TransactionBalanceRequest.cpp create mode 100644 lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp create mode 100644 lib/src/TransactionBuilder/Fee.cpp create mode 100644 lib/src/TransactionBuilder/ScriptDataHash.cpp create mode 100644 lib/src/TransactionBuilder/TransactionUtilityAccess.cpp create mode 100644 lib/src/TransactionBuilder/TransactionUtilityAccess.h create mode 100644 lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp create mode 100644 lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 32cb6d2e..92702b5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,6 +198,12 @@ ADD_LIBRARY (cometa STATIC lib/src/KeyHandlers/SecureKeyHandler.cpp lib/src/Providers/ProviderAdapter.cpp lib/src/Providers/BlockfrostProvider.cpp + lib/src/TransactionBuilder/TransactionUtilityAccess.cpp + lib/src/TransactionBuilder/Fee.cpp + lib/src/TransactionBuilder/ScriptDataHash.cpp + lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp + lib/src/TransactionBuilder/Balancing/TransactionBalanceRequest.cpp + lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp lib/src/TransactionBuilder/CoinSelectionRequest.cpp lib/src/TransactionBuilder/CoinSelectorAdapter.cpp lib/src/TransactionBuilder/LargeFirstCoinSelector.cpp @@ -725,6 +731,8 @@ IF (COMETA_BUILD_TESTS) lib/tests/Providers/BlockfrostProviderTest.cpp lib/tests/TransactionBuilder/CoinSelectorAdapterTest.cpp lib/tests/TransactionBuilder/TransactionEvaluatorAdapterTest.cpp + lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp + lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp lib/tests/TransactionBuilder/TransactionBuilderTest.cpp lib/tests/TransactionBuilder/BuilderConformanceTest.cpp lib/tests/TransactionBuilder/LifecycleConformanceTest.cpp diff --git a/doc/coverage/files.csv b/doc/coverage/files.csv index e0e0abdb..a83bdf02 100644 --- a/doc/coverage/files.csv +++ b/doc/coverage/files.csv @@ -153,7 +153,7 @@ lib/include/cardano/protocol_params/proposed_param_updates.h,public header,P12,i lib/include/cardano/protocol_params/protocol_param_update.h,public header,P12,implemented,Optional parameter proposals with distinct ledger-null states and native CBOR fixtures. lib/include/cardano/protocol_params/protocol_parameters.h,public header,P12,implemented,Cometa::ProtocolParameters lib/include/cardano/protocol_params/update.h,public header,P12,implemented,Cometa::Update -lib/include/cardano/providers/provider.h,public header,P19,planned,idiomatic C++ API +lib/include/cardano/providers/provider.h,public header,P19,implemented,Typed C++ equivalent; see function ledger for mappings and tests. lib/include/cardano/providers/provider_impl.h,public header,P19,implemented,Cometa::Provider callback adapter lib/include/cardano/scripts/native_scripts/native_script.h,public header,P06.2,implemented,"Composite requirements; independent children; threshold equality; shared native script CBOR, inspection, and hash fixtures." lib/include/cardano/scripts/native_scripts/native_script_list.h,public header,P06.2,implemented,"Composite requirements; independent children; threshold equality; shared native script CBOR, inspection, and hash fixtures." @@ -188,10 +188,10 @@ lib/include/cardano/transaction_body/transaction_input_set.h,public header,P07,i lib/include/cardano/transaction_body/transaction_output.h,public header,P07,implemented,Owned transaction values; optional datum/reference scripts; unsigned withdrawals; standard sequence aliases; shared output encodings. lib/include/cardano/transaction_body/transaction_output_list.h,public header,P07,implemented,Owned transaction values; optional datum/reference scripts; unsigned withdrawals; standard sequence aliases; shared output encodings. lib/include/cardano/transaction_body/value.h,public header,P04.2,implemented,"Signed asset values with checked arithmetic, independent components, and serialization." -lib/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h,public header,P23,planned,domain container with standard C++ iteration/value semantics; audit specialized operations -lib/include/cardano/transaction_builder/balancing/implicit_coin.h,public header,P22,planned,idiomatic C++ API -lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,public header,P22,planned,domain container with standard C++ iteration/value semantics; audit specialized operations -lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,public header,P22,planned,idiomatic C++ API +lib/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h,public header,P23,internal,Private builder and balancing bookkeeping; callbacks use DeferredRedeemer. +lib/include/cardano/transaction_builder/balancing/implicit_coin.h,public header,P22,implemented,Typed C++ equivalent; see function ledger for mappings and tests. +lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,public header,P22,internal,Private builder and balancing bookkeeping; callbacks use DeferredRedeemer. +lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,public header,P22,implemented,Typed C++ equivalent; see function ledger for mappings and tests. lib/include/cardano/transaction_builder/coin_selection/coin_selection_request.h,public header,P20,implemented,Idiomatic C++ coin selection strategy. lib/include/cardano/transaction_builder/coin_selection/coin_selection_strategy.h,public header,P20,implemented,Idiomatic C++ coin selection strategy. lib/include/cardano/transaction_builder/coin_selection/coin_selector.h,public header,P20,implemented,Idiomatic C++ coin selection strategy. @@ -202,10 +202,10 @@ lib/include/cardano/transaction_builder/evaluation/native_tx_evaluator.h,public lib/include/cardano/transaction_builder/evaluation/provider_tx_evaluator.h,public header,P21,implemented,Idiomatic C++ evaluator interface and implementations. lib/include/cardano/transaction_builder/evaluation/tx_evaluator.h,public header,P21,implemented,Idiomatic C++ evaluator interface and implementations. lib/include/cardano/transaction_builder/evaluation/tx_evaluator_impl.h,public header,P21,internal,Private native callback bridge. -lib/include/cardano/transaction_builder/fee.h,public header,P22,planned,idiomatic C++ API -lib/include/cardano/transaction_builder/script_data_hash.h,public header,P22,planned,idiomatic C++ API -lib/include/cardano/transaction_builder/sub_transaction_builder.h,public header,P23,planned,idiomatic C++ API -lib/include/cardano/transaction_builder/transaction_builder.h,public header,P22,planned,idiomatic C++ API +lib/include/cardano/transaction_builder/fee.h,public header,P22,implemented,Typed C++ equivalent; see function ledger for mappings and tests. +lib/include/cardano/transaction_builder/script_data_hash.h,public header,P22,implemented,Typed C++ equivalent; see function ledger for mappings and tests. +lib/include/cardano/transaction_builder/sub_transaction_builder.h,public header,P23,implemented,Typed C++ equivalent; see function ledger for mappings and tests. +lib/include/cardano/transaction_builder/transaction_builder.h,public header,P22,implemented,Typed C++ equivalent; see function ledger for mappings and tests. lib/include/cardano/typedefs.h,public header,P01a.1,internal,"C ABI, ownership, buffers and build metadata; map through C++ values and private support." lib/include/cardano/uplc/uplc_apply_params.h,public header,P06.3,implemented,Versioned Plutus scripts; owned bytes; versioned hashes; shared parameter application fixtures and allocation failures. lib/include/cardano/voting_procedures/governance_action_id_list.h,public header,P14,implemented,Cometa::GovernanceActionIdList diff --git a/doc/coverage/functions.csv b/doc/coverage/functions.csv index f852bb15..d9228e54 100644 --- a/doc/coverage/functions.csv +++ b/doc/coverage/functions.csv @@ -1374,11 +1374,11 @@ cardano_software_secure_key_handler_ed25519_new,lib/include/cardano/key_handlers cardano_software_secure_key_handler_deserialize,lib/include/cardano/key_handlers/software_secure_key_handler.h,P18,implemented,Cometa::SecureKeyHandler,lib/tests/KeyHandlers/SoftwareSecureKeyHandlerTest.cpp,Encrypted software signer. cardano_cip8_sign,lib/include/cardano/message_signing/cip8.h,P18,implemented,Cometa::signCip8,lib/tests/MessageSigning/Cip8Test.cpp,Address or key-hash bound COSE signing. cardano_cip8_sign_ex,lib/include/cardano/message_signing/cip8.h,P18,implemented,Cometa::signCip8,lib/tests/MessageSigning/Cip8Test.cpp,Address or key-hash bound COSE signing. -cardano_object_unref,lib/include/cardano/object.h,P01a.1,planned,,,API and ownership mapping pending. -cardano_object_ref,lib/include/cardano/object.h,P01a.1,planned,,,API and ownership mapping pending. -cardano_object_refcount,lib/include/cardano/object.h,P01a.1,planned,,,API and ownership mapping pending. -cardano_object_set_last_error,lib/include/cardano/object.h,P01a.1,planned,,,API and ownership mapping pending. -cardano_object_get_last_error,lib/include/cardano/object.h,P01a.1,planned,,,API and ownership mapping pending. +cardano_object_unref,lib/include/cardano/object.h,P01a.1,internal,Automatic ownership and private adapters,lib/tests/ValueContractTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_object_ref,lib/include/cardano/object.h,P01a.1,internal,Automatic ownership and private adapters,lib/tests/ValueContractTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_object_refcount,lib/include/cardano/object.h,P01a.1,internal,Automatic ownership and private adapters,lib/tests/ValueContractTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_object_set_last_error,lib/include/cardano/object.h,P01a.1,internal,Automatic ownership and private adapters,lib/tests/ValueContractTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_object_get_last_error,lib/include/cardano/object.h,P01a.1,internal,Automatic ownership and private adapters,lib/tests/ValueContractTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. cardano_constr_plutus_data_new,lib/include/cardano/plutus_data/constr_plutus_data.h,P05,implemented,Cometa::ConstrPlutusData::constructor,lib/tests/PlutusData/ConstrPlutusDataTest.cpp,Decoded encodings are preserved until mutation; mutable child results are independent. cardano_constr_plutus_data_from_cbor,lib/include/cardano/plutus_data/constr_plutus_data.h,P05,implemented,Cometa::ConstrPlutusData::fromCbor,lib/tests/PlutusData/ConstrPlutusDataTest.cpp,Decoded encodings are preserved until mutation; mutable child results are independent. cardano_constr_plutus_data_to_cip116_json,lib/include/cardano/plutus_data/constr_plutus_data.h,P05,implemented,Cometa::ConstrPlutusData::toJson,lib/tests/PlutusData/ConstrPlutusDataTest.cpp,Decoded encodings are preserved until mutation; mutable child results are independent. @@ -2208,23 +2208,23 @@ cardano_update_set_last_error,lib/include/cardano/protocol_params/update.h,P12,i cardano_update_get_last_error,lib/include/cardano/protocol_params/update.h,P12,internal,RAII and exception handling,lib/tests/ProtocolParams/UpdateTest.cpp; lib/tests/ValueContractTest.cpp,Epoch proposal CBOR and independent copy contract. cardano_update_deep_clone,lib/include/cardano/protocol_params/update.h,P12,implemented,Cometa::Update::copy constructor / assignment,lib/tests/ProtocolParams/UpdateTest.cpp; lib/tests/ValueContractTest.cpp,Epoch proposal CBOR and independent copy contract. cardano_provider_new,lib/include/cardano/providers/provider.h,P19,internal,,,Managed by the private Cometa::Provider adapter. -cardano_provider_get_name,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_network_magic,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_parameters,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_unspent_outputs,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_rewards_available,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_unspent_outputs_with_asset,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_unspent_output_by_nft,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_resolve_unspent_outputs,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_resolve_datum,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_confirm_transaction,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_submit_transaction,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_evaluate_transaction,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. +cardano_provider_get_name,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::name,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_network_magic,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::networkMagic,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_parameters,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::getParameters,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_unspent_outputs,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::getUnspentOutputs,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_rewards_available,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::getRewardsAvailable,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_unspent_outputs_with_asset,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::getUnspentOutputsWithAsset,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_get_unspent_output_by_nft,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::getUnspentOutputByNft,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_resolve_unspent_outputs,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::resolveUnspentOutputs,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_resolve_datum,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::resolveDatum,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_confirm_transaction,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::confirmTransaction,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_submit_transaction,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::submitTransaction,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. +cardano_provider_evaluate_transaction,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider::evaluateTransaction,lib/tests/Providers/BlockfrostProviderTest.cpp,Existing provider interface and Blockfrost implementation; ledger reconciled. cardano_provider_unref,lib/include/cardano/providers/provider.h,P19,internal,,,Managed by the private Cometa::Provider adapter. -cardano_provider_ref,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_refcount,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_set_last_error,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. -cardano_provider_get_last_error,lib/include/cardano/providers/provider.h,P19,planned,,,API and ownership mapping pending. +cardano_provider_ref,lib/include/cardano/providers/provider.h,P19,internal,Automatic ownership and private adapters,lib/tests/Providers/ProviderAdapterTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_provider_refcount,lib/include/cardano/providers/provider.h,P19,internal,Automatic ownership and private adapters,lib/tests/Providers/ProviderAdapterTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_provider_set_last_error,lib/include/cardano/providers/provider.h,P19,internal,Automatic ownership and private adapters,lib/tests/Providers/ProviderAdapterTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_provider_get_last_error,lib/include/cardano/providers/provider.h,P19,internal,Automatic ownership and private adapters,lib/tests/Providers/ProviderAdapterTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. cardano_native_script_new_all,lib/include/cardano/scripts/native_scripts/native_script.h,P06.2,implemented,Cometa::NativeScript::constructor,lib/tests/Scripts/NativeScripts/NativeScriptTest.cpp,CLI JSON input; CIP-116 inspection; preserved script encodings; standalone list headers may normalize. cardano_native_script_new_any,lib/include/cardano/scripts/native_scripts/native_script.h,P06.2,implemented,Cometa::NativeScript::constructor,lib/tests/Scripts/NativeScripts/NativeScriptTest.cpp,CLI JSON input; CIP-116 inspection; preserved script encodings; standalone list headers may normalize. cardano_native_script_new_n_of_k,lib/include/cardano/scripts/native_scripts/native_script.h,P06.2,implemented,Cometa::NativeScript::constructor,lib/tests/Scripts/NativeScripts/NativeScriptTest.cpp,CLI JSON input; CIP-116 inspection; preserved script encodings; standalone list headers may normalize. @@ -2808,26 +2808,26 @@ cardano_deferred_redeemer_list_resolve,lib/include/cardano/transaction_builder/b cardano_deferred_redeemer_list_ref,lib/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h,P23,internal,Native balancing state,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,Callbacks are retained by C++ builders. cardano_deferred_redeemer_list_unref,lib/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h,P23,internal,Native balancing state,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,Callbacks are retained by C++ builders. cardano_deferred_redeemer_list_refcount,lib/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h,P23,internal,Native balancing state,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,Callbacks are retained by C++ builders. -cardano_compute_implicit_coin,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_sub_transaction_implicit_coin,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_new,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get_length,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_insert,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get_key_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get_value_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get_key_value_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_unref,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_ref,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_refcount,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_set_last_error,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_get_last_error,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_input_to_redeemer_map_deep_clone,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,,,API and ownership mapping pending. -cardano_balance_transaction,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,planned,,,API and ownership mapping pending. -cardano_is_transaction_balanced,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_transaction_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_sub_transaction_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_transaction_batch_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,planned,,,API and ownership mapping pending. +cardano_compute_implicit_coin,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,implemented,Cometa::computeImplicitCoin,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_sub_transaction_implicit_coin,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,implemented,Cometa::computeImplicitCoin,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_input_to_redeemer_map_new,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get_length,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_insert,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get_key_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get_value_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get_key_value_at,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_unref,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_ref,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_refcount,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_set_last_error,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_get_last_error,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_input_to_redeemer_map_deep_clone,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Automatic ownership and private adapters,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,No public reference-count or last-error interface. Input-to-redeemer associations are maintained during balancing. +cardano_balance_transaction,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,implemented,Cometa::balanceTransaction,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_is_transaction_balanced,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,implemented,Cometa::isTransactionBalanced,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_transaction_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,implemented,Cometa::computeTransactionImbalance,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_sub_transaction_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,implemented,Cometa::computeSubTransactionImbalance,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_transaction_batch_imbalance,lib/include/cardano/transaction_builder/balancing/transaction_balancing.h,P22,implemented,Cometa::computeTransactionBatchImbalance,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. cardano_coin_selector_new,lib/include/cardano/transaction_builder/coin_selection/coin_selector.h,P20,internal,Cometa::createCoinSelectorAdapter,lib/tests/TransactionBuilder/CoinSelectorAdapterTest.cpp,Private native callback bridge retains the C++ selector. cardano_coin_selector_get_name,lib/include/cardano/transaction_builder/coin_selection/coin_selector.h,P20,implemented,Cometa::CoinSelector::name,lib/tests/TransactionBuilder/CoinSelectorAdapterTest.cpp,Strategy name is a C++ string. cardano_coin_selector_select,lib/include/cardano/transaction_builder/coin_selection/coin_selector.h,P20,implemented,Cometa::CoinSelector::select,lib/tests/TransactionBuilder/CoinSelectorAdapterTest.cpp,Request and result values are copied across the callback boundary. @@ -2851,92 +2851,92 @@ cardano_tx_evaluator_ref,lib/include/cardano/transaction_builder/evaluation/tx_e cardano_tx_evaluator_refcount,lib/include/cardano/transaction_builder/evaluation/tx_evaluator.h,P21,internal,C++ ownership,lib/tests/TransactionBuilder/TransactionEvaluatorAdapterTest.cpp,Reference counts are hidden from callers. cardano_tx_evaluator_set_last_error,lib/include/cardano/transaction_builder/evaluation/tx_evaluator.h,P21,internal,C++ exception translation,lib/tests/TransactionBuilder/TransactionEvaluatorAdapterTest.cpp,Native errors are translated at the callback boundary. cardano_tx_evaluator_get_last_error,lib/include/cardano/transaction_builder/evaluation/tx_evaluator.h,P21,internal,C++ exception translation,lib/tests/TransactionBuilder/TransactionEvaluatorAdapterTest.cpp,Native errors are translated at the callback boundary. -cardano_compute_transaction_fee,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_min_ada_required,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_min_script_fee,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_min_fee_without_scripts,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_script_ref_fee,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_script_ref_fee_with_params,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_get_total_ex_units_in_redeemers,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_get_serialized_coin_size,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_get_serialized_output_size,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_get_serialized_script_size,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_get_serialized_transaction_size,lib/include/cardano/transaction_builder/fee.h,P22,planned,,,API and ownership mapping pending. -cardano_compute_script_data_hash,lib/include/cardano/transaction_builder/script_data_hash.h,P22,planned,,,API and ownership mapping pending. +cardano_compute_transaction_fee,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeTransactionFee,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_min_ada_required,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeMinAdaRequired,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_min_script_fee,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeMinScriptFee,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_min_fee_without_scripts,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeMinFeeWithoutScripts,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_script_ref_fee,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeScriptRefFee,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_script_ref_fee_with_params,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::computeScriptRefFee,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_get_total_ex_units_in_redeemers,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::totalExecutionUnits,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_get_serialized_coin_size,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::serializedCoinSize,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_get_serialized_output_size,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::serializedOutputSize,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_get_serialized_script_size,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::serializedScriptSize,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_get_serialized_transaction_size,lib/include/cardano/transaction_builder/fee.h,P22,implemented,Cometa::serializedTransactionSize,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. +cardano_compute_script_data_hash,lib/include/cardano/transaction_builder/script_data_hash.h,P22,implemented,Cometa::computeScriptDataHash,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp,Owned C++ values and exceptions; native memory management stays private. cardano_sub_tx_builder_new,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::constructor,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_set_network_id,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setNetworkId,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_set_donation,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_set_donation,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setDonation,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_set_invalid_after,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setInvalidAfter,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_set_invalid_after_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_set_invalid_after_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setInvalidAfter,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,"Convert Unix seconds with SlotConfig::slotFromUnixTime, then pass the slot to the builder." cardano_sub_tx_builder_set_invalid_before,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setInvalidBefore,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_set_invalid_before_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_set_invalid_before_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setInvalidBefore,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,"Convert Unix seconds with SlotConfig::slotFromUnixTime, then pass the slot to the builder." cardano_sub_tx_builder_add_input,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addInput,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_input_with_deferred_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addInputWithDeferredRedeemer,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,C++ callback receives independent draft and input values. cardano_sub_tx_builder_add_reference_input,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addReferenceInput,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_output,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addOutput,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_send_lovelace,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::sendLovelace,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_send_lovelace_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_send_lovelace_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::sendLovelace,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_send_value,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::sendValue,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_send_value_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_send_value_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::sendValue,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_lock_lovelace,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::lockLovelace,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_lock_lovelace_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_lock_lovelace_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::lockLovelace,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_lock_value,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::lockValue,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_lock_value_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_lock_value_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::lockValue,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_set_metadata,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setMetadata,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_set_metadata_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_mint_token,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_set_metadata_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::setMetadata,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Parse plain metadata JSON with Metadatum::fromPlainJson before setMetadata. +cardano_sub_tx_builder_mint_token,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::mintToken,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_sub_tx_builder_mint_token_with_deferred_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::mintTokenWithDeferredRedeemer,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ callback receives independent draft and input values. -cardano_sub_tx_builder_mint_token_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_mint_token_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::mintToken,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_sub_tx_builder_mint_token_with_id,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::mintToken,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_mint_token_with_id_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_mint_token_with_id_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::mintToken,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_sub_tx_builder_add_script,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addScript,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_signer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addSigner,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_add_signer_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_add_signer_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addSigner,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_add_guard,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addGuard,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_add_guard_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_add_guard_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addGuard,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_add_guard_with_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addGuard,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_datum,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addDatum,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_require_top_level_guard,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::requireTopLevelGuard,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_require_top_level_guard_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_require_top_level_guard_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::requireTopLevelGuard,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_add_direct_deposit,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addDirectDeposit,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_add_direct_deposit_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_add_direct_deposit_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addDirectDeposit,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_add_account_balance_interval,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addAccountBalanceInterval,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_add_account_balance_interval_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_add_account_balance_interval_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addAccountBalanceInterval,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_withdraw_rewards,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::withdrawRewards,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_withdraw_rewards_with_deferred_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::withdrawRewardsWithDeferredRedeemer,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_withdraw_rewards_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_withdraw_rewards_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::withdrawRewards,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_register_reward_address,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::registerRewardAddress,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_register_reward_address_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_register_reward_address_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::registerRewardAddress,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_deregister_reward_address,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::deregisterRewardAddress,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_deregister_reward_address_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_deregister_reward_address_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::deregisterRewardAddress,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_delegate_stake,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::delegateStake,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_delegate_stake_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_delegate_stake_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::delegateStake,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_delegate_voting_power,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::delegateVotingPower,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_delegate_voting_power_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_delegate_voting_power_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::delegateVotingPower,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_register_drep,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::registerDRep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_register_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_register_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::registerDrep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_update_drep,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::updateDRep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_update_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_update_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::updateDrep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_deregister_drep,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::deregisterDRep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_deregister_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_deregister_drep_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::deregisterDrep,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_sub_tx_builder_vote,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::vote,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_vote_with_deferred_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::voteWithDeferredRedeemer,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_certificate,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addCertificate,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_add_certificate_with_deferred_redeemer,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::addCertificateWithDeferredRedeemer,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_sub_tx_builder_propose_parameter_change,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_parameter_change_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_hardfork,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_hardfork_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_treasury_withdrawals,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_treasury_withdrawals_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_no_confidence,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_no_confidence_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_update_committee,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_update_committee_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_new_constitution,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_new_constitution_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_info,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. -cardano_sub_tx_builder_propose_info_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,planned,,,API and ownership mapping pending. +cardano_sub_tx_builder_propose_parameter_change,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeParameterChange,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_parameter_change_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeParameterChange,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_hardfork,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeHardFork,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_hardfork_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeHardFork,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_treasury_withdrawals,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeTreasuryWithdrawals,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_treasury_withdrawals_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeTreasuryWithdrawals,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_no_confidence,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeNoConfidence,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_no_confidence_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeNoConfidence,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_update_committee,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeUpdateCommittee,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_update_committee_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeUpdateCommittee,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_new_constitution,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeNewConstitution,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_new_constitution_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeNewConstitution,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_info,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeInfo,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_sub_tx_builder_propose_info_ex,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::proposeInfo,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. cardano_sub_tx_builder_build,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,implemented,Cometa::SubTransactionBuilder::build,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_sub_tx_builder_unref,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,internal,C++ ownership,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Builder lifecycle is automatic. cardano_sub_tx_builder_ref,lib/include/cardano/transaction_builder/sub_transaction_builder.h,P23,internal,C++ ownership,lib/tests/TransactionBuilder/SubTransactionBuilderTest.cpp,Builder lifecycle is automatic. @@ -2948,86 +2948,86 @@ cardano_tx_builder_set_coin_selector,lib/include/cardano/transaction_builder/tra cardano_tx_builder_set_tx_evaluator,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setTransactionEvaluator,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_network_id,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setNetworkId,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_change_address,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setChangeAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_set_change_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_set_change_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setChangeAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_set_collateral_change_address,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setCollateralChangeAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_set_collateral_change_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_set_collateral_change_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setCollateralChangeAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_set_minimum_fee,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setMinimumFee,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_donation,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setDonation,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_utxos,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setUtxos,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_collateral_utxos,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setCollateralUtxos,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_invalid_after,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setInvalidAfter,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_set_invalid_after_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_set_invalid_after_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setInvalidAfter,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,"Convert Unix seconds with SlotConfig::slotFromUnixTime, then pass the slot to the builder." cardano_tx_builder_set_invalid_before,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setInvalidBefore,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_set_invalid_before_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_set_invalid_before_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setInvalidBefore,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,"Convert Unix seconds with SlotConfig::slotFromUnixTime, then pass the slot to the builder." cardano_tx_builder_add_reference_input,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addReferenceInput,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_send_lovelace,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::sendLovelace,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_send_lovelace_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_send_lovelace_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::sendLovelace,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_send_value,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::sendValue,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_send_value_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_send_value_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::sendValue,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_lock_lovelace,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::lockLovelace,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_lock_lovelace_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_lock_lovelace_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::lockLovelace,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_lock_value,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::lockValue,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_lock_value_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_lock_value_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::lockValue,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_input,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addInput,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_input_with_deferred_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addInputWithDeferredRedeemer,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,C++ callback receives independent draft and input values. cardano_tx_builder_add_output,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addOutput,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_set_metadata,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setMetadata,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_set_metadata_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_mint_token,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_set_metadata_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::setMetadata,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Parse plain metadata JSON with Metadatum::fromPlainJson before setMetadata. +cardano_tx_builder_mint_token,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::mintToken,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_tx_builder_mint_token_with_deferred_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::mintTokenWithDeferredRedeemer,lib/tests/TransactionBuilder/DeferredRedeemerAdapterTest.cpp,C++ callback receives independent draft and input values. -cardano_tx_builder_mint_token_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_mint_token_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::mintToken,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_tx_builder_mint_token_with_id,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::mintToken,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_mint_token_with_id_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_mint_token_with_id_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::mintToken,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,AssetId combines the policy hash and asset name; mintToken takes the typed identifier. cardano_tx_builder_pad_signer_count,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::padSignerCount,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_signer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addSigner,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_add_signer_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_add_signer_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addSigner,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_guard,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addGuard,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_add_guard_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_add_guard_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addGuard,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_guard_with_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addGuard,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_datum,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addDatum,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_withdraw_rewards,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::withdrawRewards,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_withdraw_rewards_with_deferred_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::withdrawRewardsWithDeferredRedeemer,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_withdraw_rewards_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_withdraw_rewards_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::withdrawRewards,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_direct_deposit,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addDirectDeposit,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_add_direct_deposit_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_add_direct_deposit_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addDirectDeposit,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_account_balance_interval,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addAccountBalanceInterval,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_add_account_balance_interval_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_add_account_balance_interval_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addAccountBalanceInterval,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_starting_account_balance_interval,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addStartingAccountBalanceInterval,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_add_starting_account_balance_interval_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_add_starting_account_balance_interval_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addStartingAccountBalanceInterval,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_add_sub_transaction,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addSubTransaction,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_register_reward_address,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::registerRewardAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_register_reward_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_register_reward_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::registerRewardAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_deregister_reward_address,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::deregisterRewardAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_deregister_reward_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_deregister_reward_address_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::deregisterRewardAddress,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_delegate_stake,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::delegateStake,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_delegate_stake_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_delegate_stake_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::delegateStake,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_delegate_voting_power,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::delegateVotingPower,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_delegate_voting_power_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_delegate_voting_power_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::delegateVotingPower,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_register_drep,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::registerDRep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_register_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_register_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::registerDrep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_update_drep,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::updateDRep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_update_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_update_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::updateDrep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_deregister_drep,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::deregisterDRep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_deregister_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_deregister_drep_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::deregisterDrep,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Typed C++ arguments replace string-based C convenience variants. cardano_tx_builder_vote,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::vote,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_vote_with_deferred_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::voteWithDeferredRedeemer,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_certificate,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addCertificate,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_certificate_with_deferred_redeemer,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addCertificateWithDeferredRedeemer,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_add_script,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::addScript,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_propose_parameter_change,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_parameter_change_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_hardfork,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_hardfork_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_propose_parameter_change,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeParameterChange,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_parameter_change_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeParameterChange,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_hardfork,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeHardFork,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_hardfork_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeHardFork,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. cardano_tx_builder_propose_treasury_withdrawals,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeTreasuryWithdrawals,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_propose_treasury_withdrawals_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_no_confidence,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_no_confidence_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_update_committee,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_update_committee_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_new_constitution,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. -cardano_tx_builder_propose_new_constitution_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_propose_treasury_withdrawals_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeTreasuryWithdrawals,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_no_confidence,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeNoConfidence,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_no_confidence_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeNoConfidence,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_update_committee,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeUpdateCommittee,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_update_committee_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeUpdateCommittee,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_new_constitution,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeNewConstitution,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. +cardano_tx_builder_propose_new_constitution_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeNewConstitution,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. cardano_tx_builder_propose_info,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeInfo,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. -cardano_tx_builder_propose_info_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,planned,,,API and ownership mapping pending. +cardano_tx_builder_propose_info_ex,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::proposeInfo,lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp,Typed proposals support optional predecessor IDs; parameter and treasury proposals require a guardrails policy hash. cardano_tx_builder_build,lib/include/cardano/transaction_builder/transaction_builder.h,P22,implemented,Cometa::TransactionBuilder::build,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,C++ values and scoped native ownership. cardano_tx_builder_unref,lib/include/cardano/transaction_builder/transaction_builder.h,P22,internal,C++ ownership,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Builder lifecycle is automatic. cardano_tx_builder_ref,lib/include/cardano/transaction_builder/transaction_builder.h,P22,internal,C++ ownership,lib/tests/TransactionBuilder/TransactionBuilderTest.cpp,Builder lifecycle is automatic. diff --git a/doc/coverage/types.csv b/doc/coverage/types.csv index 0850ff0b..e54acb75 100644 --- a/doc/coverage/types.csv +++ b/doc/coverage/types.csv @@ -88,9 +88,9 @@ cardano_governance_action_type_t,enum,lib/include/cardano/proposal_procedures/go cardano_governance_key_type_t,enum,lib/include/cardano/common/governance_key_type.h,P01a.1,implemented,GovernanceKeyType,lib/tests/Common/GovernanceKeyTypeTest.cpp cardano_guard_set_t,opaque object,lib/include/cardano/common/guard_set.h,P16,implemented,Cometa::GuardSet,lib/tests/TransactionBody/GuardSetTest.cpp; lib/tests/ValueContractTest.cpp cardano_hard_fork_initiation_action_t,opaque object,lib/include/cardano/proposal_procedures/hard_fork_initiation_action.h,P13,implemented,Cometa::HardForkInitiationAction,lib/tests/ProposalProcedures/HardForkInitiationActionTest.cpp; lib/tests/ValueContractTest.cpp -cardano_implicit_coin_t,struct,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,planned,, +cardano_implicit_coin_t,struct,lib/include/cardano/transaction_builder/balancing/implicit_coin.h,P22,implemented,Cometa::ImplicitCoin,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp cardano_info_action_t,opaque object,lib/include/cardano/proposal_procedures/info_action.h,P13,implemented,Cometa::InfoAction,lib/tests/ProposalProcedures/InfoActionTest.cpp; lib/tests/ValueContractTest.cpp -cardano_input_to_redeemer_map_t,opaque object,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,planned,, +cardano_input_to_redeemer_map_t,opaque object,lib/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h,P22,internal,Private input-to-redeemer associations in balanceTransaction,lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp cardano_ipv4_t,opaque object,lib/include/cardano/pool_params/ipv4.h,P09,implemented,Cometa::Ipv4,lib/tests/PoolParams/Ipv4Test.cpp; lib/tests/ValueContractTest.cpp cardano_ipv6_t,opaque object,lib/include/cardano/pool_params/ipv6.h,P09,implemented,Cometa::Ipv6,lib/tests/PoolParams/Ipv6Test.cpp; lib/tests/ValueContractTest.cpp cardano_json_context_t,enum,lib/include/cardano/json/json_context.h,P01b,implemented,Cometa::JsonContext,lib/tests/Json/JsonContextTest.cpp @@ -154,7 +154,7 @@ cardano_protocol_param_update_t,opaque object,lib/include/cardano/protocol_param cardano_protocol_parameters_t,opaque object,lib/include/cardano/protocol_params/protocol_parameters.h,P12,implemented,Cometa::ProtocolParameters,lib/tests/ProtocolParams/ProtocolParametersTest.cpp cardano_protocol_version_t,opaque object,lib/include/cardano/common/protocol_version.h,P01a.1,implemented,ProtocolVersion,lib/tests/Common/ProtocolVersionTest.cpp cardano_provider_impl_t,struct,lib/include/cardano/providers/provider_impl.h,P19,internal,, -cardano_provider_t,opaque object,lib/include/cardano/providers/provider.h,P19,planned,, +cardano_provider_t,opaque object,lib/include/cardano/providers/provider.h,P19,implemented,Cometa::Provider,lib/tests/Providers/BlockfrostProviderTest.cpp cardano_redeemer_list_t,opaque object,lib/include/cardano/witness_set/redeemer_list.h,P15,implemented,Cometa::RedeemerList,lib/tests/WitnessSet/RedeemerListTest.cpp; lib/tests/ValueContractTest.cpp cardano_redeemer_t,opaque object,lib/include/cardano/witness_set/redeemer.h,P15,implemented,Cometa::Redeemer,lib/tests/WitnessSet/RedeemerTest.cpp cardano_redeemer_tag_t,enum,lib/include/cardano/witness_set/redeemer_tag.h,P15,implemented,Cometa::RedeemerTag,lib/tests/WitnessSet/RedeemerTagTest.cpp diff --git a/doc/src/coverage.rst b/doc/src/coverage.rst index fa4e2d2d..34342347 100644 --- a/doc/src/coverage.rst +++ b/doc/src/coverage.rst @@ -84,10 +84,9 @@ ownership. See :doc:`getting_started` for usage. Coverage ledger --------------- -The inventory is a planning snapshot from cardano-c commit -``fd108f6271b4caf3df65907e21ffc5f5ea0bce55``. The build revision is pinned -separately in ``cmake/Cardano.cmake``. Reconcile this ledger against that revision -before treating its status columns as a current completeness measure. +The inventory was reconciled against the pinned cardano-c commit +``af8780f200bc8a604324fb1a93a974283094022d``. All exported declarations +in that revision have a mapping; no entries remain planned. It contains 231 public headers, 418 implementation files, 235 distinct public typedefs, and 3,335 exported function declarations. Tests and vendored dependencies are outside the file inventory. @@ -102,7 +101,7 @@ are outside the file inventory. standard containers, or private adapters; it is not a claim that every internal C operation has a dedicated C++ test. ``planned`` entries remain unfinished. Function rows name the C++ operation and its associated test suite when available. -Detailed ownership audits remain part of implementing each planned operation. +The ledger records API availability, not line or branch test coverage. Passing tests or the shared corpus does not establish complete API coverage. diff --git a/doc/src/sections/api/transaction_builder/fee.rst b/doc/src/sections/api/transaction_builder/fee.rst new file mode 100644 index 00000000..1a5f36c4 --- /dev/null +++ b/doc/src/sections/api/transaction_builder/fee.rst @@ -0,0 +1,26 @@ +Fees and serialized sizes +========================= + +``#include `` + +.. doxygenfunction:: Cometa::computeTransactionFee + +.. doxygenfunction:: Cometa::computeMinAdaRequired + +.. doxygenfunction:: Cometa::computeMinScriptFee + +.. doxygenfunction:: Cometa::computeMinFeeWithoutScripts + +.. doxygenfunction:: Cometa::computeScriptRefFee(const UtxoList&, const UnitInterval&) + +.. doxygenfunction:: Cometa::computeScriptRefFee(const UtxoList&, const ProtocolParameters&) + +.. doxygenfunction:: Cometa::serializedCoinSize + +.. doxygenfunction:: Cometa::serializedOutputSize + +.. doxygenfunction:: Cometa::serializedScriptSize + +.. doxygenfunction:: Cometa::serializedTransactionSize + +.. doxygenfunction:: Cometa::totalExecutionUnits diff --git a/doc/src/sections/api/transaction_builder/implicit_coin.rst b/doc/src/sections/api/transaction_builder/implicit_coin.rst new file mode 100644 index 00000000..40df212f --- /dev/null +++ b/doc/src/sections/api/transaction_builder/implicit_coin.rst @@ -0,0 +1,11 @@ +Withdrawals and deposits +======================== + +``#include `` + +.. doxygenstruct:: Cometa::ImplicitCoin + :members: + +.. doxygenfunction:: Cometa::computeImplicitCoin(const Transaction&, const ProtocolParameters&) + +.. doxygenfunction:: Cometa::computeImplicitCoin(const SubTransaction&, const ProtocolParameters&) diff --git a/doc/src/sections/api/transaction_builder/index.rst b/doc/src/sections/api/transaction_builder/index.rst index 000ba33d..aa48dc53 100644 --- a/doc/src/sections/api/transaction_builder/index.rst +++ b/doc/src/sections/api/transaction_builder/index.rst @@ -10,6 +10,11 @@ SubTransactionBuilder builds Dijkstra intents for inclusion in a batch. :maxdepth: 1 usage + fee + script_data_hash + implicit_coin + transaction_balance_request + transaction_balancing coin_selection_request coin_selection_result coin_selector diff --git a/doc/src/sections/api/transaction_builder/script_data_hash.rst b/doc/src/sections/api/transaction_builder/script_data_hash.rst new file mode 100644 index 00000000..43d065a2 --- /dev/null +++ b/doc/src/sections/api/transaction_builder/script_data_hash.rst @@ -0,0 +1,6 @@ +Script data hash +================ + +``#include `` + +.. doxygenfunction:: Cometa::computeScriptDataHash diff --git a/doc/src/sections/api/transaction_builder/transaction_balance_request.rst b/doc/src/sections/api/transaction_builder/transaction_balance_request.rst new file mode 100644 index 00000000..b01d0898 --- /dev/null +++ b/doc/src/sections/api/transaction_builder/transaction_balance_request.rst @@ -0,0 +1,7 @@ +TransactionBalanceRequest +========================= + +``#include `` + +.. doxygenstruct:: Cometa::TransactionBalanceRequest + :members: diff --git a/doc/src/sections/api/transaction_builder/transaction_balancing.rst b/doc/src/sections/api/transaction_builder/transaction_balancing.rst new file mode 100644 index 00000000..e82a74ec --- /dev/null +++ b/doc/src/sections/api/transaction_builder/transaction_balancing.rst @@ -0,0 +1,14 @@ +Transaction balancing +===================== + +``#include `` + +.. doxygenfunction:: Cometa::computeTransactionImbalance + +.. doxygenfunction:: Cometa::computeSubTransactionImbalance + +.. doxygenfunction:: Cometa::computeTransactionBatchImbalance + +.. doxygenfunction:: Cometa::isTransactionBalanced + +.. doxygenfunction:: Cometa::balanceTransaction diff --git a/doc/src/sections/api/transaction_builder/usage.rst b/doc/src/sections/api/transaction_builder/usage.rst index e02db71f..571609c4 100644 --- a/doc/src/sections/api/transaction_builder/usage.rst +++ b/doc/src/sections/api/transaction_builder/usage.rst @@ -79,3 +79,45 @@ redeemer data depends on the balanced transaction. The callback receives the current draft and resolved inputs; the builder may invoke it more than once, so it should return the same data for the same draft. The complete batch and deferred-redeemer examples are in ``examples/``. + +Transaction utilities +--------------------- + +Use ``computeMinAdaRequired`` to price an output before adding it to a transaction. +``computeTransactionFee`` prices the current transaction, including its existing +witnesses and execution budgets. It does not reserve space for signatures that +have not yet been added; the builder and standalone balancer account for those. + +.. code-block:: cpp + + const std::uint64_t minimum = Cometa::computeMinAdaRequired( + output, parameters.adaPerUtxoByte()); + + const Cometa::Value imbalance = Cometa::computeTransactionImbalance( + transaction, resolvedInputs, parameters); + +A positive imbalance is surplus value; a negative imbalance is a deficit. +``computeTransactionBatchImbalance`` includes sub-transactions. +``computeImplicitCoin`` reports withdrawals, certificate deposits and refunds, +and governance proposal deposits. Pool registration state still needs to be +checked against the chain when deciding whether a pool deposit is due. + +To balance an existing unsigned draft, provide its resolved spending inputs and +available funds. The result includes the fee and change; the original draft is +unchanged. Sign the returned transaction. Use ``TransactionBuilder`` when a +redeemer must be computed after balancing. + +.. code-block:: cpp + + Cometa::TransactionBalanceRequest request( + draft, parameters, changeAddress, slotConfig); + + request.available = availableUtxos; + request.collateral = collateralUtxos; + request.coinSelector = std::make_shared(); + + const Cometa::Transaction balanced = Cometa::balanceTransaction(request); + +``request.evaluator`` accepts the same ``TransactionEvaluator`` interface as the +builder. When no services are supplied, balancing uses random-improve selection +and local Plutus evaluation with the request's network parameters and slot timeline. diff --git a/lib/include/Cometa/Cometa.h b/lib/include/Cometa/Cometa.h index 05ec822b..d7da7458 100644 --- a/lib/include/Cometa/Cometa.h +++ b/lib/include/Cometa/Cometa.h @@ -253,3 +253,9 @@ #include #include #include + +#include +#include +#include +#include +#include diff --git a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h index 3e436bed..9879644d 100644 --- a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h +++ b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h @@ -796,6 +796,9 @@ class ProtocolParameters private: + /** @brief Allows transaction utilities to read protocol parameters. */ + friend class TransactionUtilityAccess; + /** @brief Allows the provider bridge to copy parameters into native calls. */ friend class ProviderAdapter; diff --git a/lib/include/Cometa/TransactionBuilder/Balancing/ImplicitCoin.h b/lib/include/Cometa/TransactionBuilder/Balancing/ImplicitCoin.h new file mode 100644 index 00000000..5a4a09de --- /dev/null +++ b/lib/include/Cometa/TransactionBuilder/Balancing/ImplicitCoin.h @@ -0,0 +1,77 @@ +/** + * @file ImplicitCoin.h + * + * @brief Implicit transaction lovelace accounting. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include +#include +#include + +#include + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** + * @brief Lovelace entering or leaving a transaction through rewards and deposits. + * + * Pool registrations are treated as new registrations because no chain registration state is queried. + * Pool retirement refunds occur at an epoch boundary and are not included here. + */ +struct ImplicitCoin +{ + /** @brief Reward withdrawals available to the transaction, in lovelace. */ + std::uint64_t withdrawals = 0; + + /** @brief Certificate and governance deposits paid, in lovelace. */ + std::uint64_t deposits = 0; + + /** @brief Certificate deposits reclaimed, in lovelace. */ + std::uint64_t reclaimDeposits = 0; +}; + +/** + * @brief Computes rewards, deposits, and deposit refunds. + * + * The result does not include UTxO values, fees, minting, or treasury donations. + * @param transaction The transaction to inspect. + * @param parameters The current protocol parameters for the target network. + * @return The implicit lovelace components. + * @throws Error The operation cannot be completed with the supplied values. + */ +ImplicitCoin computeImplicitCoin(const Transaction& transaction, const ProtocolParameters& parameters); + +/** + * @brief Computes rewards, deposits, and deposit refunds. + * + * The result does not include UTxO values, fees, minting, or treasury donations. + * @param transaction The transaction to inspect. + * @param parameters The current protocol parameters for the target network. + * @return The implicit lovelace components. + * @throws Error The operation cannot be completed with the supplied values. + */ +ImplicitCoin computeImplicitCoin(const SubTransaction& transaction, const ProtocolParameters& parameters); +} // namespace Cometa diff --git a/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalanceRequest.h b/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalanceRequest.h new file mode 100644 index 00000000..2d23105c --- /dev/null +++ b/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalanceRequest.h @@ -0,0 +1,97 @@ +/** + * @file TransactionBalanceRequest.h + * + * @brief Inputs and services for standalone transaction balancing. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** + * @brief An unsigned draft, its available funds, and the network context for balancing. + * + * Initial spending inputs are resolved from preselected or available UTxOs. Additional preselected + * inputs are mandatory. Provide batch spending and reference UTxOs in available or referenceInputs. + */ +struct TransactionBalanceRequest +{ + /** + * @brief Creates a balancing request without changing the supplied draft. + * @param transaction The unsigned draft to balance. + * @param parameters Current network parameters. + * @param changeAddress The address receiving surplus value. + * @param slots The network slot timeline used by the default evaluator. + */ + TransactionBalanceRequest(Transaction transaction, ProtocolParameters parameters, Address changeAddress, SlotConfig slots); + + /** @brief The unsigned draft; top-level key signatures must be absent. */ + Transaction transaction; + + /** @brief Network fees, deposits, limits, and Plutus cost models. */ + ProtocolParameters parameters; + + /** @brief The address receiving ordinary change. */ + Address changeAddress; + + /** @brief The timeline used by the default local evaluator. */ + SlotConfig slots; + + /** @brief UTxOs that must be spent in addition to the draft's initial inputs. */ + UtxoList preselected; + + /** @brief UTxOs eligible for selection, also resolving the draft and batch inputs. */ + UtxoList available; + + /** @brief Resolved reference inputs and any additional batch input context. */ + UtxoList referenceInputs; + + /** @brief UTxOs available as collateral when Plutus redeemers are present. */ + UtxoList collateral; + + /** @brief The collateral return address; defaults to changeAddress when absent. */ + std::optional
collateralChangeAddress; + + /** @brief Additional signing keys whose witness size must be included in fee estimation. */ + std::size_t foreignSignatureCount = 0; + + /** @brief The selection service; an empty pointer selects random-improve. */ + std::shared_ptr coinSelector; + + /** @brief The evaluation service; an empty pointer selects local Plutus evaluation. */ + std::shared_ptr evaluator; +}; +} // namespace Cometa diff --git a/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalancing.h b/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalancing.h new file mode 100644 index 00000000..b0de4449 --- /dev/null +++ b/lib/include/Cometa/TransactionBuilder/Balancing/TransactionBalancing.h @@ -0,0 +1,94 @@ +/** + * @file TransactionBalancing.h + * + * @brief Transaction value conservation and standalone balancing. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** + * @brief Computes consumed minus produced value for the top-level transaction body. + * + * This is value accounting, not script or full ledger validation. + * @param transaction The transaction to inspect. + * @param resolvedInputs The resolved spending inputs. + * @param parameters The current protocol parameters for the target network. + * @return Positive quantities are surplus; negative quantities are a deficit. + * @throws Error The operation cannot be completed with the supplied values. + */ +Value computeTransactionImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Computes consumed minus produced value for a sub-transaction. + * + * This is value accounting, not script or full ledger validation. + * @param transaction The transaction to inspect. + * @param resolvedInputs The resolved spending inputs. + * @param parameters The current protocol parameters for the target network. + * @return Positive quantities are surplus; negative quantities are a deficit. + * @throws Error The operation cannot be completed with the supplied values. + */ +Value computeSubTransactionImbalance(const SubTransaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Computes the combined value imbalance of a transaction and its sub-transactions. + * + * This is value accounting, not script or full ledger validation. + * @param transaction The transaction to inspect. + * @param resolvedInputs The resolved spending inputs, including batch inputs when computing batch imbalance. + * @param parameters The current protocol parameters for the target network. + * @return Positive quantities are surplus; negative quantities are a deficit. + * @throws Error The operation cannot be completed with the supplied values. + */ +Value computeTransactionBatchImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Checks whether the transaction and its sub-transactions have zero combined imbalance. + * + * This does not check fee adequacy, signatures, or script validity. + * @param transaction The transaction to inspect. + * @param resolvedInputs The resolved spending inputs of the transaction and any sub-transactions. + * @param parameters The current protocol parameters for the target network. + * @return True when consumed and produced values match. + * @throws Error The operation cannot be completed with the supplied values. + */ +bool isTransactionBalanced(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Balances a copy of an unsigned transaction. + * + * Existing spending redeemers are associated with their original inputs and reindexed after selection. + * The request and its transaction remain unchanged on success or failure. + * Use TransactionBuilder for deferred redeemer producers. + * @param request The draft, resolved UTxOs, network context, and optional services. + * @return A balanced transaction ready to sign. + * @throws Error The operation cannot be completed with the supplied values. + * @throws std::invalid_argument The draft contains key signatures, an unresolved initial input, or an invalid spending redeemer index. + */ +Transaction balanceTransaction(const TransactionBalanceRequest& request); +} // namespace Cometa diff --git a/lib/include/Cometa/TransactionBuilder/Fee.h b/lib/include/Cometa/TransactionBuilder/Fee.h new file mode 100644 index 00000000..a745fa1e --- /dev/null +++ b/lib/include/Cometa/TransactionBuilder/Fee.h @@ -0,0 +1,147 @@ +/** + * @file Fee.h + * + * @brief Fee calculations and serialized size measurements. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include +#include +#include +#include + +#include +#include + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** + * @brief Computes the minimum fee for a transaction or batch. + * + * Uses the supplied reference-script pricing parameters. Inputs are not changed. + * @param transaction The complete transaction, including any witness sizes to price. + * @param resolvedInputs Resolved spend and reference inputs; include every priced occurrence, including those in sub-transactions. + * @param parameters The current protocol parameters for the target network. + * @return The fee in lovelace. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeTransactionFee(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Computes an output's minimum lovelace requirement. + * @param output The proposed output. + * @param coinsPerUtxoByte The protocol cost in lovelace per accounted UTxO byte. + * @return The minimum lovelace amount. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeMinAdaRequired(const TransactionOutput& output, std::uint64_t coinsPerUtxoByte); + +/** + * @brief Computes execution and reference-script fees. + * + * Uses Conway reference-script pricing tiers; use computeTransactionFee() for protocol-specific pricing. + * @param transaction The complete transaction, including any witness sizes to price. + * @param prices Lovelace prices for execution memory and steps. + * @param resolvedInputs Resolved spend and reference inputs; include every priced occurrence, including those in sub-transactions. + * @param coinsPerRefScriptByte The reference-script fee rate in lovelace per byte. + * @return The script fee in lovelace. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeMinScriptFee(const Transaction& transaction, const ExUnitPrices& prices, const UtxoList& resolvedInputs, const UnitInterval& coinsPerRefScriptByte); + +/** + * @brief Computes the size-dependent fee without script charges. + * + * The ledger fee size excludes the transaction validity flag. + * @param transaction The complete transaction, including any witness sizes to price. + * @param constant The constant fee term in lovelace. + * @param coefficient The fee per serialized transaction byte. + * @return The fee in lovelace. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeMinFeeWithoutScripts(const Transaction& transaction, std::uint64_t constant, std::uint64_t coefficient); + +/** + * @brief Computes reference-script fees using Conway pricing tiers. + * @param resolvedInputs Resolved spend and reference inputs; include every priced occurrence, including those in sub-transactions. + * @param coinsPerRefScriptByte The reference-script fee rate in lovelace per byte. + * @return The reference-script fee in lovelace. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const UnitInterval& coinsPerRefScriptByte); + +/** + * @brief Computes reference-script fees using network pricing parameters. + * + * Unset stride and multiplier parameters use Conway defaults. + * @param resolvedInputs Resolved spend and reference inputs; include every priced occurrence, including those in sub-transactions. + * @param parameters The current protocol parameters for the target network. + * @return The reference-script fee in lovelace. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + +/** + * @brief Computes the CBOR size of a lovelace amount. + * @param lovelace The amount to encode. + * @return The encoded size in bytes. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::size_t serializedCoinSize(std::uint64_t lovelace); + +/** + * @brief Computes an output's serialized size. + * @param output The output to measure. + * @return The size in bytes. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::size_t serializedOutputSize(const TransactionOutput& output); + +/** + * @brief Computes the ledger script size used for reference-script pricing. + * + * The measure depends on the script language; it is not necessarily Script::toCbor().size(). + * @param script The script to measure. + * @return The script size in bytes. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::size_t serializedScriptSize(const Script& script); + +/** + * @brief Computes a complete transaction's serialized size. + * @param transaction The complete transaction, including any witness sizes to price. + * @return The size in bytes, including its current witnesses. + * @throws Error The fee or size cannot be computed from the supplied values. + */ +std::size_t serializedTransactionSize(const Transaction& transaction); + +/** + * @brief Sums the memory and execution-step budgets of redeemers. + * @param redeemers The redeemers whose budgets are added. + * @return The total execution budget. + * @throws Error A component of the sum exceeds the 64-bit unsigned range. + */ +ExUnits totalExecutionUnits(const RedeemerList& redeemers); +} // namespace Cometa diff --git a/lib/include/Cometa/TransactionBuilder/ScriptDataHash.h b/lib/include/Cometa/TransactionBuilder/ScriptDataHash.h new file mode 100644 index 00000000..8da99e0d --- /dev/null +++ b/lib/include/Cometa/TransactionBuilder/ScriptDataHash.h @@ -0,0 +1,48 @@ +/** + * @file ScriptDataHash.h + * + * @brief Transaction script-data commitments. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include +#include +#include +#include + +#include + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** + * @brief Computes the commitment to redeemers, witness datums, and language views. + * @param costModels Only the language views required by the transaction. + * @param redeemers The final redeemers and their execution budgets. + * @param datums Witness datums; inline output datums are not included. + * @return The 32-byte commitment, or std::nullopt when both data collections are empty. + * @throws Error The operation cannot be completed with the supplied values. + */ +std::optional computeScriptDataHash(const CostModels& costModels, const RedeemerList& redeemers, const PlutusDataSet& datums); +} // namespace Cometa diff --git a/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h b/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h index 60587d4a..6d9c0e03 100644 --- a/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h +++ b/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h @@ -32,14 +32,21 @@ #include #include #include +#include #include #include #include #include +#include +#include #include +#include #include #include +#include +#include #include +#include #include #include #include @@ -103,6 +110,13 @@ class SubTransactionBuilder */ SubTransactionBuilder& setNetworkId(NetworkId network); + /** + * @brief Sets a treasury donation in the intent. + * @param lovelace The amount donated to the treasury, in lovelace. + * @return This builder. + */ + SubTransactionBuilder& setDonation(std::uint64_t lovelace); + /** * @brief Sets the earliest valid slot. * @@ -471,6 +485,118 @@ class SubTransactionBuilder const Credential& guard, const std::optional& datum = std::nullopt); + /** + * @brief Proposes selected protocol parameter changes. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param update The proposed parameter changes. + * @param policyHash The constitution guardrails script hash; add its script to the builder. + * @param previousAction The preceding action, or std::nullopt for no predecessor. + * @return This builder. + */ + SubTransactionBuilder& proposeParameterChange( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolParamUpdate& update, + const Blake2bHash& policyHash, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes a ledger protocol-version upgrade. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param version The proposed major and minor protocol version. + * @param previousAction The preceding action, or std::nullopt for no predecessor. + * @return This builder. + */ + SubTransactionBuilder& proposeHardFork( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolVersion& version, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes no confidence in the constitutional committee. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param previousAction The preceding committee action, or std::nullopt when absent. + * @return This builder. + */ + SubTransactionBuilder& proposeNoConfidence( + const RewardAddress& refundAddress, + const Anchor& anchor, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes committee membership and quorum changes. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param removedMembers Cold credentials to remove. + * @param addedMembers New cold credentials and their expiry epochs. + * @param quorum The proposed voting quorum fraction. + * @param previousAction The preceding committee action, or std::nullopt when absent. + * @return This builder. + */ + SubTransactionBuilder& proposeUpdateCommittee( + const RewardAddress& refundAddress, + const Anchor& anchor, + const CredentialSet& removedMembers, + const CommitteeMembersMap& addedMembers, + const UnitInterval& quorum, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes a replacement constitution. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param constitution The new constitution anchor and optional guardrails script. + * @param previousAction The preceding constitution action, or std::nullopt when absent. + * @return This builder. + */ + SubTransactionBuilder& proposeNewConstitution( + const RewardAddress& refundAddress, + const Anchor& anchor, + const Constitution& constitution, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes an informational governance action. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @return This builder. + */ + SubTransactionBuilder& proposeInfo( + const RewardAddress& refundAddress, + const Anchor& anchor); + + /** + * @brief Proposes payments from the treasury to reward accounts. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param withdrawals Recipient reward accounts and amounts in lovelace. + * @param policyHash The constitution guardrails script hash; add its script to the builder. + * @return This builder. + */ + SubTransactionBuilder& proposeTreasuryWithdrawals( + const RewardAddress& refundAddress, + const Anchor& anchor, + const WithdrawalMap& withdrawals, + const Blake2bHash& policyHash); + /** * @brief Builds one sub-transaction. * diff --git a/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h b/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h index 0b761aad..38590727 100644 --- a/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h +++ b/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h @@ -32,15 +32,21 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include #include #include +#include +#include #include +#include #include #include #include @@ -623,6 +629,90 @@ class TransactionBuilder */ TransactionBuilder& padSignerCount(std::size_t count); + /** + * @brief Proposes selected protocol parameter changes. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param update The proposed parameter changes. + * @param policyHash The constitution guardrails script hash; add its script to the builder. + * @param previousAction The preceding action, or std::nullopt for no predecessor. + * @return This builder. + */ + TransactionBuilder& proposeParameterChange( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolParamUpdate& update, + const Blake2bHash& policyHash, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes a ledger protocol-version upgrade. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param version The proposed major and minor protocol version. + * @param previousAction The preceding action, or std::nullopt for no predecessor. + * @return This builder. + */ + TransactionBuilder& proposeHardFork( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolVersion& version, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes no confidence in the constitutional committee. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param previousAction The preceding committee action, or std::nullopt when absent. + * @return This builder. + */ + TransactionBuilder& proposeNoConfidence( + const RewardAddress& refundAddress, + const Anchor& anchor, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes committee membership and quorum changes. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param removedMembers Cold credentials to remove. + * @param addedMembers New cold credentials and their expiry epochs. + * @param quorum The proposed voting quorum fraction. + * @param previousAction The preceding committee action, or std::nullopt when absent. + * @return This builder. + */ + TransactionBuilder& proposeUpdateCommittee( + const RewardAddress& refundAddress, + const Anchor& anchor, + const CredentialSet& removedMembers, + const CommitteeMembersMap& addedMembers, + const UnitInterval& quorum, + const std::optional& previousAction = std::nullopt); + + /** + * @brief Proposes a replacement constitution. + * + * The governance deposit is taken from the configured protocol parameters. + * @param refundAddress The reward account receiving the deposit refund. + * @param anchor Metadata describing the proposal. + * @param constitution The new constitution anchor and optional guardrails script. + * @param previousAction The preceding constitution action, or std::nullopt when absent. + * @return This builder. + */ + TransactionBuilder& proposeNewConstitution( + const RewardAddress& refundAddress, + const Anchor& anchor, + const Constitution& constitution, + const std::optional& previousAction = std::nullopt); + /** * @brief Builds a balanced transaction ready for signing. * diff --git a/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp b/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp new file mode 100644 index 00000000..8a024763 --- /dev/null +++ b/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp @@ -0,0 +1,62 @@ +/** + * @file ImplicitCoin.cpp + * + * @brief Implicit transaction lovelace accounting. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include + +#include "../../CardanoInterop.h" +#include "../TransactionUtilityAccess.h" + +#include +#include +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +ImplicitCoin +computeImplicitCoin(const Transaction& transaction, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + + cardano_implicit_coin_t result {}; + checkCardanoError(cardano_compute_implicit_coin(nativeTransaction.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeImplicitCoin"); + + return ImplicitCoin { result.withdrawals, result.deposits, result.reclaim_deposits }; +} + +ImplicitCoin +computeImplicitCoin(const SubTransaction& transaction, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_sub_transaction_from_cbor)); + + cardano_implicit_coin_t result {}; + checkCardanoError(cardano_compute_sub_transaction_implicit_coin(nativeTransaction.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeImplicitCoin"); + + return ImplicitCoin { result.withdrawals, result.deposits, result.reclaim_deposits }; +} +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/Balancing/TransactionBalanceRequest.cpp b/lib/src/TransactionBuilder/Balancing/TransactionBalanceRequest.cpp new file mode 100644 index 00000000..7e94d754 --- /dev/null +++ b/lib/src/TransactionBuilder/Balancing/TransactionBalanceRequest.cpp @@ -0,0 +1,45 @@ +/** + * @file TransactionBalanceRequest.cpp + * + * @brief Standalone balancing request values. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include + +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +TransactionBalanceRequest::TransactionBalanceRequest( + Transaction transaction, + ProtocolParameters parameters, + Address changeAddress, + SlotConfig slots) +: transaction(std::move(transaction)) +, parameters(std::move(parameters)) +, changeAddress(std::move(changeAddress)) +, slots(slots) +{ +} +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp new file mode 100644 index 00000000..edd2fec8 --- /dev/null +++ b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp @@ -0,0 +1,241 @@ +/** + * @file TransactionBalancing.cpp + * + * @brief Transaction value conservation and standalone balancing. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include +#include +#include + +#include "../../CardanoInterop.h" +#include "../CoinSelectorAdapter.h" +#include "../TransactionEvaluatorAdapter.h" +#include "../TransactionUtilityAccess.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +Value +computeTransactionImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + cardano_value_t* result = nullptr; + const cardano_error_t status = cardano_compute_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + CardanoObject owner(result); + + checkCardanoError(status, "computeTransactionImbalance"); + + return TransactionUtilityAccess::copyValue(owner.get()); +} + +Value +computeSubTransactionImbalance(const SubTransaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_sub_transaction_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + cardano_value_t* result = nullptr; + const cardano_error_t status = cardano_compute_sub_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + CardanoObject owner(result); + + checkCardanoError(status, "computeSubTransactionImbalance"); + + return TransactionUtilityAccess::copyValue(owner.get()); +} + +Value +computeTransactionBatchImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + cardano_value_t* result = nullptr; + const cardano_error_t status = cardano_compute_transaction_batch_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + CardanoObject owner(result); + + checkCardanoError(status, "computeTransactionBatchImbalance"); + + return TransactionUtilityAccess::copyValue(owner.get()); +} + +bool +isTransactionBalanced(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + bool result {}; + checkCardanoError(cardano_is_transaction_balanced(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "isTransactionBalanced"); + + return result; +} + +Transaction +balanceTransaction(const TransactionBalanceRequest& request) +{ + const WitnessSet witnesses = request.transaction.witnessSet(); + const std::optional keys = witnesses.vkeys(); + const std::optional bootstrap = witnesses.bootstrap(); + + if ((keys && !keys->empty()) || (bootstrap && !bootstrap->empty())) + { + throw std::invalid_argument("Balance an unsigned draft before collecting top-level signatures"); + } + + const TransactionInputSet inputs = request.transaction.body().inputs(); + UtxoList selected = request.preselected; + + for (const TransactionInput& input: inputs) + { + bool found = false; + + for (const Utxo& utxo: selected) + { + if (utxo.input() == input) + { + found = true; + break; + } + } + + if (!found) + { + for (const Utxo& utxo: request.available) + { + if (utxo.input() == input) + { + selected.push_back(utxo); + found = true; + break; + } + } + } + + if (!found) + { + throw std::invalid_argument("An initial spending input is not resolved by preselected or available UTxOs"); + } + } + + CardanoObject transaction( + decodeCbor(request.transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject preselected(copyUtilityUtxos(selected)); + CardanoObject available(copyUtilityUtxos(request.available)); + CardanoObject references(copyUtilityUtxos(request.referenceInputs)); + CardanoObject collateral(copyUtilityUtxos(request.collateral)); + CardanoObject change(copyUtilityAddress(request.changeAddress)); + CardanoObject collateralChange( + copyUtilityAddress(request.collateralChangeAddress ? *request.collateralChangeAddress : request.changeAddress)); + + cardano_input_to_redeemer_map_t* mapValue = nullptr; + const cardano_error_t mapStatus = cardano_input_to_redeemer_map_new(&mapValue); + CardanoObject inputRedeemers(mapValue); + + checkCardanoError(mapStatus, "Input redeemer associations"); + + const std::optional redeemers = witnesses.redeemers(); + + if (redeemers) + { + CardanoObject nativeWitnesses(cardano_transaction_get_witness_set(transaction.get())); + CardanoObject nativeRedeemers(cardano_witness_set_get_redeemers(nativeWitnesses.get())); + + for (std::size_t index = 0; index < redeemers->size(); ++index) + { + const Redeemer redeemer = redeemers->at(index); + + if (redeemer.tag() != RedeemerTag::Spend) + { + continue; + } + + if (redeemer.index() >= inputs.size()) + { + throw std::invalid_argument("A spending redeemer refers to an input outside the draft"); + } + + const TransactionInput input = inputs.at(static_cast(redeemer.index())); + CardanoObject nativeInput( + decodeCbor(input.toCbor(), cardano_transaction_input_from_cbor)); + + cardano_redeemer_t* value = nullptr; + const cardano_error_t status = cardano_redeemer_list_get(nativeRedeemers.get(), index, &value); + CardanoObject nativeRedeemer(value); + + checkCardanoError(status, "Spending redeemer lookup"); + + checkCardanoError(cardano_input_to_redeemer_map_insert(inputRedeemers.get(), nativeInput.get(), nativeRedeemer.get()), "Input redeemer insertion"); + } + } + + std::shared_ptr selector = request.coinSelector; + std::shared_ptr evaluator = request.evaluator; + + if (!selector) + { + selector = std::make_shared(); + } + + if (!evaluator) + { + evaluator = std::make_shared( + request.slots, request.parameters.costModels(), request.parameters.protocolVersion().major()); + } + + CardanoObject nativeSelector(createCoinSelectorAdapter(selector)); + CardanoObject nativeEvaluator(createTransactionEvaluatorAdapter(evaluator)); + + cardano_transaction_clear_cbor_cache(transaction.get()); + + const cardano_error_t status = cardano_balance_transaction( + transaction.get(), request.foreignSignatureCount, TransactionUtilityAccess::parameters(request.parameters), references.get(), preselected.get(), inputRedeemers.get(), available.get(), nativeSelector.get(), change.get(), collateral.get(), collateralChange.get(), nativeEvaluator.get(), nullptr); + + checkCardanoError(status, "balanceTransaction"); + cardano_transaction_clear_cbor_cache(transaction.get()); + + return Transaction::fromCbor(encodeCbor(transaction.get(), cardano_transaction_to_cbor)); +} + +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/Fee.cpp b/lib/src/TransactionBuilder/Fee.cpp new file mode 100644 index 00000000..348f12cd --- /dev/null +++ b/lib/src/TransactionBuilder/Fee.cpp @@ -0,0 +1,196 @@ +/** + * @file Fee.cpp + * + * @brief Fee calculations and serialized size measurements. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include + +#include "../CardanoInterop.h" +#include "TransactionUtilityAccess.h" + +#include +#include +#include +#include +#include + +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +std::uint64_t +computeTransactionFee(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_transaction_fee(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeTransactionFee"); + + return result; +} + +std::uint64_t +computeMinAdaRequired(const TransactionOutput& output, std::uint64_t coinsPerUtxoByte) +{ + CardanoObject nativeOutput( + decodeCbor(output.toCbor(), cardano_transaction_output_from_cbor)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_min_ada_required(nativeOutput.get(), coinsPerUtxoByte, &result), "computeMinAdaRequired"); + + return result; +} + +std::uint64_t +computeMinScriptFee(const Transaction& transaction, const ExUnitPrices& prices, const UtxoList& resolvedInputs, const UnitInterval& coinsPerRefScriptByte) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + CardanoObject nativePrices( + decodeCbor(prices.toCbor(), cardano_ex_unit_prices_from_cbor)); + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeCoinsPerRefScriptByte( + decodeCbor(coinsPerRefScriptByte.toCbor(), cardano_unit_interval_from_cbor)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_min_script_fee(nativeTransaction.get(), nativePrices.get(), nativeResolvedInputs.get(), nativeCoinsPerRefScriptByte.get(), &result), "computeMinScriptFee"); + + return result; +} + +std::uint64_t +computeMinFeeWithoutScripts(const Transaction& transaction, std::uint64_t constant, std::uint64_t coefficient) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_min_fee_without_scripts(nativeTransaction.get(), constant, coefficient, &result), "computeMinFeeWithoutScripts"); + + return result; +} + +std::uint64_t +computeScriptRefFee(const UtxoList& resolvedInputs, const UnitInterval& coinsPerRefScriptByte) +{ + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeCoinsPerRefScriptByte( + decodeCbor(coinsPerRefScriptByte.toCbor(), cardano_unit_interval_from_cbor)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_script_ref_fee(nativeResolvedInputs.get(), nativeCoinsPerRefScriptByte.get(), &result), "computeScriptRefFee"); + + return result; +} + +std::uint64_t +computeScriptRefFee(const UtxoList& resolvedInputs, const ProtocolParameters& parameters) +{ + CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + + std::uint64_t result {}; + checkCardanoError(cardano_compute_script_ref_fee_with_params(nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeScriptRefFee"); + + return result; +} + +std::size_t +serializedCoinSize(std::uint64_t lovelace) +{ + std::size_t result {}; + checkCardanoError(cardano_get_serialized_coin_size(lovelace, &result), "serializedCoinSize"); + + return result; +} + +std::size_t +serializedOutputSize(const TransactionOutput& output) +{ + CardanoObject nativeOutput( + decodeCbor(output.toCbor(), cardano_transaction_output_from_cbor)); + + std::size_t result {}; + checkCardanoError(cardano_get_serialized_output_size(nativeOutput.get(), &result), "serializedOutputSize"); + + return result; +} + +std::size_t +serializedScriptSize(const Script& script) +{ + CardanoObject nativeScript( + decodeCbor(script.toCbor(), cardano_script_from_cbor)); + + std::size_t result {}; + checkCardanoError(cardano_get_serialized_script_size(nativeScript.get(), &result), "serializedScriptSize"); + + return result; +} + +std::size_t +serializedTransactionSize(const Transaction& transaction) +{ + CardanoObject nativeTransaction( + decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); + + std::size_t result {}; + checkCardanoError(cardano_get_serialized_transaction_size(nativeTransaction.get(), &result), "serializedTransactionSize"); + + return result; +} + +ExUnits +totalExecutionUnits(const RedeemerList& redeemers) +{ + std::uint64_t memory = 0; + std::uint64_t steps = 0; + + for (const Redeemer& redeemer: redeemers) + { + const ExUnits units = redeemer.exUnits(); + + if (units.memory() > std::numeric_limits::max() - memory || units.cpuSteps() > std::numeric_limits::max() - steps) + { + throw Error(ErrorCode::IntegerOverflow, "totalExecutionUnits"); + } + + memory += units.memory(); + steps += units.cpuSteps(); + } + + CardanoObject nativeRedeemers( + decodeCbor(redeemers.toCbor(), cardano_redeemer_list_from_cbor)); + + cardano_ex_units_t* result = nullptr; + const cardano_error_t status = cardano_get_total_ex_units_in_redeemers(nativeRedeemers.get(), &result); + CardanoObject owner(result); + + checkCardanoError(status, "totalExecutionUnits"); + + return ExUnits::fromCbor(encodeCbor(owner.get(), cardano_ex_units_to_cbor)); +} +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/ScriptDataHash.cpp b/lib/src/TransactionBuilder/ScriptDataHash.cpp new file mode 100644 index 00000000..ed4f8a0b --- /dev/null +++ b/lib/src/TransactionBuilder/ScriptDataHash.cpp @@ -0,0 +1,60 @@ +/** + * @file ScriptDataHash.cpp + * + * @brief Transaction script-data commitments. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include + +#include "../CardanoInterop.h" + +#include +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +std::optional +computeScriptDataHash(const CostModels& costModels, const RedeemerList& redeemers, const PlutusDataSet& datums) +{ + CardanoObject nativeCostModels( + decodeCbor(costModels.toCbor(), cardano_costmdls_from_cbor)); + CardanoObject nativeRedeemers( + decodeCbor(redeemers.toCbor(), cardano_redeemer_list_from_cbor)); + CardanoObject nativeDatums( + decodeCbor(datums.toCbor(), cardano_plutus_data_set_from_cbor)); + + cardano_blake2b_hash_t* result = nullptr; + const cardano_error_t status = cardano_compute_script_data_hash(nativeCostModels.get(), nativeRedeemers.get(), nativeDatums.get(), &result); + CardanoObject owner(result); + + checkCardanoError(status, "computeScriptDataHash"); + + if (!owner) + { + return std::nullopt; + } + + return Blake2bHash::fromCbor(encodeCbor(owner.get(), cardano_blake2b_hash_to_cbor)); +} +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/SubTransactionBuilder.cpp b/lib/src/TransactionBuilder/SubTransactionBuilder.cpp index 39eda5b8..2a8f999a 100644 --- a/lib/src/TransactionBuilder/SubTransactionBuilder.cpp +++ b/lib/src/TransactionBuilder/SubTransactionBuilder.cpp @@ -39,9 +39,16 @@ #include #include #include +#include +#include #include +#include #include #include +#include +#include +#include +#include #include #include #include @@ -161,6 +168,14 @@ SubTransactionBuilder::setNetworkId(NetworkId network) return *this; } +SubTransactionBuilder& +SubTransactionBuilder::setDonation(std::uint64_t lovelace) +{ + cardano_sub_tx_builder_set_donation(checked(), lovelace); + + return *this; +} + SubTransactionBuilder& SubTransactionBuilder::setInvalidBefore(std::uint64_t slot) { @@ -636,6 +651,160 @@ SubTransactionBuilder::build() return SubTransaction::fromCbor(encodeCbor(owner.get(), cardano_sub_transaction_to_cbor)); } +SubTransactionBuilder& +SubTransactionBuilder::proposeParameterChange( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolParamUpdate& update, + const Blake2bHash& policyHash, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeUpdate( + decodeCbor(update.toCbor(), cardano_protocol_param_update_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + CardanoObject nativePolicyHash( + decodeCbor(policyHash.toCbor(), cardano_blake2b_hash_from_cbor)); + + cardano_sub_tx_builder_propose_parameter_change(checked(), nativeAddress.get(), nativeAnchor.get(), nativeUpdate.get(), nativePreviousAction.get(), nativePolicyHash.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeHardFork( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolVersion& version, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeVersion( + decodeCbor(version.toCbor(), cardano_protocol_version_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_sub_tx_builder_propose_hardfork(checked(), nativeAddress.get(), nativeAnchor.get(), nativeVersion.get(), nativePreviousAction.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeNoConfidence( + const RewardAddress& refundAddress, + const Anchor& anchor, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_sub_tx_builder_propose_no_confidence(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeUpdateCommittee( + const RewardAddress& refundAddress, + const Anchor& anchor, + const CredentialSet& removedMembers, + const CommitteeMembersMap& addedMembers, + const UnitInterval& quorum, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeRemovedMembers( + decodeCbor(removedMembers.toCbor(), cardano_credential_set_from_cbor)); + + CardanoObject nativeAddedMembers( + decodeCbor(addedMembers.toCbor(), cardano_committee_members_map_from_cbor)); + + CardanoObject nativeQuorum( + decodeCbor(quorum.toCbor(), cardano_unit_interval_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_sub_tx_builder_propose_update_committee(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get(), nativeRemovedMembers.get(), nativeAddedMembers.get(), nativeQuorum.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeNewConstitution( + const RewardAddress& refundAddress, + const Anchor& anchor, + const Constitution& constitution, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeConstitution( + decodeCbor(constitution.toCbor(), cardano_constitution_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_sub_tx_builder_propose_new_constitution(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get(), nativeConstitution.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeInfo( + const RewardAddress& refundAddress, + const Anchor& anchor) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + cardano_sub_tx_builder_propose_info(checked(), nativeAddress.get(), nativeAnchor.get()); + + return *this; +} + +SubTransactionBuilder& +SubTransactionBuilder::proposeTreasuryWithdrawals( + const RewardAddress& refundAddress, + const Anchor& anchor, + const WithdrawalMap& withdrawals, + const Blake2bHash& policyHash) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeWithdrawals( + decodeCbor(withdrawals.toCbor(), cardano_withdrawal_map_from_cbor)); + + CardanoObject nativePolicyHash( + decodeCbor(policyHash.toCbor(), cardano_blake2b_hash_from_cbor)); + + cardano_sub_tx_builder_propose_treasury_withdrawals(checked(), nativeAddress.get(), nativeAnchor.get(), nativeWithdrawals.get(), nativePolicyHash.get()); + + return *this; +} + SubTransactionBuilder& SubTransactionBuilder::operator=(SubTransactionBuilder&& other) noexcept { diff --git a/lib/src/TransactionBuilder/TransactionBuilder.cpp b/lib/src/TransactionBuilder/TransactionBuilder.cpp index 18e6fdb1..f1a30cff 100644 --- a/lib/src/TransactionBuilder/TransactionBuilder.cpp +++ b/lib/src/TransactionBuilder/TransactionBuilder.cpp @@ -41,11 +41,17 @@ #include #include #include +#include +#include #include #include #include #include #include +#include +#include +#include +#include #include #include #include @@ -797,6 +803,124 @@ TransactionBuilder::build() return Transaction::fromCbor(encodeCbor(owner.get(), cardano_transaction_to_cbor)); } +TransactionBuilder& +TransactionBuilder::proposeParameterChange( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolParamUpdate& update, + const Blake2bHash& policyHash, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeUpdate( + decodeCbor(update.toCbor(), cardano_protocol_param_update_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + CardanoObject nativePolicyHash( + decodeCbor(policyHash.toCbor(), cardano_blake2b_hash_from_cbor)); + + cardano_tx_builder_propose_parameter_change(checked(), nativeAddress.get(), nativeAnchor.get(), nativeUpdate.get(), nativePreviousAction.get(), nativePolicyHash.get()); + + return *this; +} + +TransactionBuilder& +TransactionBuilder::proposeHardFork( + const RewardAddress& refundAddress, + const Anchor& anchor, + const ProtocolVersion& version, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeVersion( + decodeCbor(version.toCbor(), cardano_protocol_version_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_tx_builder_propose_hardfork(checked(), nativeAddress.get(), nativeAnchor.get(), nativeVersion.get(), nativePreviousAction.get()); + + return *this; +} + +TransactionBuilder& +TransactionBuilder::proposeNoConfidence( + const RewardAddress& refundAddress, + const Anchor& anchor, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_tx_builder_propose_no_confidence(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get()); + + return *this; +} + +TransactionBuilder& +TransactionBuilder::proposeUpdateCommittee( + const RewardAddress& refundAddress, + const Anchor& anchor, + const CredentialSet& removedMembers, + const CommitteeMembersMap& addedMembers, + const UnitInterval& quorum, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeRemovedMembers( + decodeCbor(removedMembers.toCbor(), cardano_credential_set_from_cbor)); + + CardanoObject nativeAddedMembers( + decodeCbor(addedMembers.toCbor(), cardano_committee_members_map_from_cbor)); + + CardanoObject nativeQuorum( + decodeCbor(quorum.toCbor(), cardano_unit_interval_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_tx_builder_propose_update_committee(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get(), nativeRemovedMembers.get(), nativeAddedMembers.get(), nativeQuorum.get()); + + return *this; +} + +TransactionBuilder& +TransactionBuilder::proposeNewConstitution( + const RewardAddress& refundAddress, + const Anchor& anchor, + const Constitution& constitution, + const std::optional& previousAction) +{ + CardanoObject nativeAddress(copyRewardAddress(refundAddress)); + CardanoObject nativeAnchor( + decodeCbor(anchor.toCbor(), cardano_anchor_from_cbor)); + + CardanoObject nativeConstitution( + decodeCbor(constitution.toCbor(), cardano_constitution_from_cbor)); + + CardanoObject nativePreviousAction( + previousAction ? decodeCbor(previousAction->toCbor(), cardano_governance_action_id_from_cbor) : nullptr); + + cardano_tx_builder_propose_new_constitution(checked(), nativeAddress.get(), nativeAnchor.get(), nativePreviousAction.get(), nativeConstitution.get()); + + return *this; +} + TransactionBuilder& TransactionBuilder::operator=(TransactionBuilder&& other) noexcept { diff --git a/lib/src/TransactionBuilder/TransactionUtilityAccess.cpp b/lib/src/TransactionBuilder/TransactionUtilityAccess.cpp new file mode 100644 index 00000000..e6197e83 --- /dev/null +++ b/lib/src/TransactionBuilder/TransactionUtilityAccess.cpp @@ -0,0 +1,90 @@ +/** + * @file TransactionUtilityAccess.cpp + * + * @brief Private parameter and UTxO conversion for transaction utilities. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include "TransactionUtilityAccess.h" +#include "../CardanoInterop.h" + +#include +#include +#include +#include +#include + +/* FUNCTIONS IMPLEMENTATION **************************************************/ + +namespace Cometa +{ +cardano_protocol_parameters_t* +TransactionUtilityAccess::parameters(const ProtocolParameters& parameters) +{ + return parameters.checked(); +} + +Value +TransactionUtilityAccess::copyValue(cardano_value_t* value) +{ + CardanoObject assets(cardano_value_get_multi_asset(value)); + + if (!assets) + { + return Value(cardano_value_get_coin(value)); + } + + return Value(cardano_value_get_coin(value), MultiAsset::fromCbor(encodeCbor(assets.get(), cardano_multi_asset_to_cbor))); +} + +cardano_utxo_list_t* +copyUtilityUtxos(const UtxoList& utxos) +{ + cardano_utxo_list_t* value = nullptr; + const cardano_error_t status = cardano_utxo_list_new(&value); + CardanoObject owner(value); + + checkCardanoError(status, "UTxO list"); + + for (const Utxo& utxo: utxos) + { + CardanoObject item( + decodeCbor(utxo.toCbor(), cardano_utxo_from_cbor)); + + checkCardanoError(cardano_utxo_list_add(owner.get(), item.get()), "UTxO list insertion"); + } + + return owner.release(); +} + +cardano_address_t* +copyUtilityAddress(const Address& address) +{ + const std::vector bytes = address.toBytes(); + cardano_address_t* value = nullptr; + const cardano_error_t status = cardano_address_from_bytes(bytes.data(), bytes.size(), &value); + CardanoObject owner(value); + + checkCardanoError(status, "Address conversion"); + + return owner.release(); +} +} // namespace Cometa diff --git a/lib/src/TransactionBuilder/TransactionUtilityAccess.h b/lib/src/TransactionBuilder/TransactionUtilityAccess.h new file mode 100644 index 00000000..b3cbd1e0 --- /dev/null +++ b/lib/src/TransactionBuilder/TransactionUtilityAccess.h @@ -0,0 +1,77 @@ +/** + * @file TransactionUtilityAccess.h + * + * @brief Private access used by transaction utilities. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include +#include +#include +#include + +/* FORWARD DECLARATIONS ******************************************************/ + +struct cardano_protocol_parameters_t; +struct cardano_utxo_list_t; +struct cardano_address_t; + +/* DECLARATIONS **************************************************************/ + +namespace Cometa +{ +/** @brief Provides internal parameter access for transaction utilities. */ +class TransactionUtilityAccess +{ + public: + + /** + * @brief Gets the parameters borrowed for the duration of a utility call. + * @param parameters The owning C++ parameters. + * @return The borrowed native parameters. + */ + static cardano_protocol_parameters_t* parameters(const ProtocolParameters& parameters); + + /** + * @brief Copies a newly computed signed value. + * @param value The borrowed native value. + * @return The signed C++ value. + */ + static Value copyValue(cardano_value_t* value); +}; + +/** + * @brief Copies resolved outputs into an owned native list. + * @param utxos The outputs to copy. + * @return The owned list. + */ +cardano_utxo_list_t* copyUtilityUtxos(const UtxoList& utxos); + +/** + * @brief Copies a change address into an owned native value. + * @param address The address to copy. + * @return The owned address. + */ +cardano_address_t* copyUtilityAddress(const Address& address); + +} // namespace Cometa diff --git a/lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp b/lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp new file mode 100644 index 00000000..41a94c0b --- /dev/null +++ b/lib/tests/TransactionBuilder/GovernanceBuilderTest.cpp @@ -0,0 +1,167 @@ +/** + * @file GovernanceBuilderTest.cpp + * + * @brief Tests standalone transaction operations and governance construction. + * + * @author angel.castillo + * @date Nov 03, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include +#include +#include + +#include + +/* USINGS ********************************************************************/ + +using namespace Cometa; + +/* INTERNAL IMPLEMENTATION ***************************************************/ + +namespace +{ +/** @brief Builds the seven governance proposals. @tparam Builder The builder type. @param builder The builder. @param predecessor Whether to include a predecessor. @return The independently constructed expected proposals. */ +template +ProposalProcedureSet +addAllProposals(Builder& builder, bool predecessor) +{ + const Credential credential(CredentialType::KeyHash, Blake2bHash(std::vector(28, 4))); + const RewardAddress reward(NetworkId::Testnet, credential); + const Anchor anchor("https://example.com/action", Blake2bHash(std::vector(32, 5))); + const GovernanceActionId id(Blake2bHash(std::vector(32, 6)), 3); + const std::optional previous = predecessor ? std::optional(id) : std::nullopt; + ProtocolParamUpdate update; + update.setMinFeeA(47); + + WithdrawalMap withdrawals; + withdrawals.set(reward, 2'000'000); + const CredentialSet removed { credential }; + CommitteeMembersMap added; + added.insert(Credential(CredentialType::KeyHash, Blake2bHash(std::vector(28, 8))), 500); + const UnitInterval quorum(2, 3); + const Constitution constitution(anchor); + const ProtocolVersion version(12, 1); + + const Script policy(PlutusV4Script::fromHex("450100002499")); + const Blake2bHash policyHash = policy.hash(); + + builder.addScript(policy); + + builder.proposeParameterChange(reward, anchor, update, policyHash, previous) + .proposeHardFork(reward, anchor, version, previous) + .proposeTreasuryWithdrawals(reward, anchor, withdrawals, policyHash) + .proposeNoConfidence(reward, anchor, previous) + .proposeUpdateCommittee(reward, anchor, removed, added, quorum, previous) + .proposeNewConstitution(reward, anchor, constitution, previous) + .proposeInfo(reward, anchor); + + return ProposalProcedureSet { + ProposalProcedure(1'000'000, reward, anchor, ParameterChangeAction(update, previous, policyHash)), + ProposalProcedure(1'000'000, reward, anchor, HardForkInitiationAction(version, previous)), + ProposalProcedure(1'000'000, reward, anchor, TreasuryWithdrawalsAction(withdrawals, policyHash)), + ProposalProcedure(1'000'000, reward, anchor, NoConfidenceAction(previous)), + ProposalProcedure(1'000'000, reward, anchor, UpdateCommitteeAction(removed, added, quorum, previous)), + ProposalProcedure(1'000'000, reward, anchor, NewConstitutionAction(constitution, previous)), + ProposalProcedure(1'000'000, reward, anchor, InfoAction()) + }; +} + +/** @brief Supplies the presence or absence of predecessor IDs. */ +class GovernanceBuilder : public testing::TestWithParam +{ +}; + +/** @brief Creates protocol parameters for deterministic proposal tests. @return The parameters. */ +ProtocolParameters +parameters() +{ + ProtocolParameters result; + result.setProtocolVersion(ProtocolVersion(12, 0)); + result.setMinFeeA(44); + result.setMinFeeB(155381); + result.setAdaPerUtxoByte(4310); + result.setMaxTxSize(65536); + result.setGovernanceActionDeposit(1'000'000); + + CostModels models; + models.insert(CostModel(PlutusLanguageVersion::V4, std::vector(179, 0))); + result.setCostModels(models); + + return result; +} + +/** @brief Creates a funded payment output. @return The UTxO. */ +Utxo +funding() +{ + const Credential credential(CredentialType::KeyHash, Blake2bHash(std::vector(28, 1))); + const Address address = EnterpriseAddress(NetworkId::Testnet, credential); + + return Utxo(TransactionInput(Blake2bHash(std::vector(32, 2)), 0), TransactionOutput(address, Value(20'000'000))); +} +} // namespace + +/* IMPLEMENTATION ************************************************************/ + +TEST_P(GovernanceBuilder, BuildsEveryTopLevelProposal) +{ + // Arrange + const Utxo input = funding(); + TransactionBuilder builder(parameters(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + + const Utxo collateral(TransactionInput(Blake2bHash(std::vector(32, 9)), 0), input.output()); + + builder.setUtxos({ input }) + .setChangeAddress(input.output().address()) + .setCollateralUtxos({ collateral }) + .setCollateralChangeAddress(input.output().address()); + const ProposalProcedureSet expected = addAllProposals(builder, GetParam()); + + // Act + const Transaction transaction = builder.build(); + + // Assert + ASSERT_TRUE(transaction.body().proposalProcedures()); + EXPECT_EQ(transaction.body().proposalProcedures()->toCbor(), expected.toCbor()); + EXPECT_EQ(computeImplicitCoin(transaction, parameters()).deposits, 7'000'000U); + EXPECT_TRUE(isTransactionBalanced(transaction, { input }, parameters())); +} + +TEST_P(GovernanceBuilder, BuildsEverySubTransactionProposalAndDonation) +{ + // Arrange + const Utxo input = funding(); + SubTransactionBuilder builder(parameters(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + + builder.addInput(input).sendLovelace(input.output().address(), 12'500'000).setDonation(500'000); + const ProposalProcedureSet expected = addAllProposals(builder, GetParam()); + + // Act + const SubTransaction transaction = builder.build(); + + // Assert + ASSERT_TRUE(transaction.body().proposalProcedures()); + EXPECT_EQ(transaction.body().proposalProcedures()->toCbor(), expected.toCbor()); + EXPECT_EQ(transaction.body().donation(), 500'000U); + EXPECT_EQ(computeImplicitCoin(transaction, parameters()).deposits, 7'000'000U); + EXPECT_TRUE(computeSubTransactionImbalance(transaction, { input }, parameters()).isZero()); +} + +INSTANTIATE_TEST_SUITE_P(Predecessors, GovernanceBuilder, testing::Bool()); diff --git a/lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp b/lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp new file mode 100644 index 00000000..b62aeeb8 --- /dev/null +++ b/lib/tests/TransactionBuilder/TransactionUtilitiesTest.cpp @@ -0,0 +1,542 @@ +/** + * @file TransactionUtilitiesTest.cpp + * + * @brief Tests standalone transaction operations and governance construction. + * + * @author angel.castillo + * @date Nov 03, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* INCLUDES ******************************************************************/ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +/* USINGS ********************************************************************/ + +using namespace Cometa; + +/* INTERNAL IMPLEMENTATION ***************************************************/ + +namespace +{ +/** @brief Creates test protocol parameters. @return The parameters. */ +ProtocolParameters +parameters() +{ + ProtocolParameters result; + result.setProtocolVersion(ProtocolVersion(12, 0)); + result.setMinFeeA(44); + result.setMinFeeB(155381); + result.setAdaPerUtxoByte(4310); + result.setMaxTxSize(16384); + result.setKeyDeposit(2'000'000); + result.setGovernanceActionDeposit(1'000'000); + result.setExecutionCosts(ExUnitPrices(UnitInterval(1, 2), UnitInterval(1, 4))); + result.setRefScriptCostPerByte(UnitInterval(2, 1)); + + return result; +} + +/** @brief Creates a payment address. @return The address. */ +Address +address() +{ + return EnterpriseAddress(NetworkId::Testnet, Credential(CredentialType::KeyHash, Blake2bHash(std::vector(28, 1)))); +} + +/** @brief Creates a funded output. @param byte The transaction ID byte. @param coin The lovelace value. @return The UTxO. */ +Utxo +funding(std::uint8_t byte = 2, std::int64_t coin = 10'000'000) +{ + return Utxo(TransactionInput(Blake2bHash(std::vector(32, byte)), 0), TransactionOutput(address(), Value(coin))); +} + +/** @brief Creates a draft payment. @return The unsigned draft. */ +Transaction +draft() +{ + return Transaction(TransactionBody(TransactionInputSet(), TransactionOutputList { TransactionOutput(address(), Value(3'000'000)) }, 0), WitnessSet()); +} + +/** @brief Counts evaluator calls without evaluating scripts. */ +class CountingEvaluator : public TransactionEvaluator +{ + public: + + /** @brief Number of evaluation invocations. */ + mutable std::size_t calls = 0; + + /** @brief Gets the test evaluator name. @return The name. */ + std::string + name() const override + { + return "counting"; + } + + /** @brief Returns the draft's budgets. @param transaction The draft. @param additionalUtxos Resolved context. @return Existing redeemers or an empty list. */ + RedeemerList + evaluate(const Transaction& transaction, const UtxoList& additionalUtxos) const override + { + (void)additionalUtxos; + ++calls; + return transaction.witnessSet().redeemers().value_or(RedeemerList()); + } +}; + +/** @brief Counts selection calls and can simulate a service failure. */ +class CountingSelector : public CoinSelector +{ + public: + + /** @brief Number of selection invocations. */ + mutable std::size_t calls = 0; + + /** @brief Whether selection should fail. */ + bool fail = false; + + /** @brief Gets the test selector name. @return The name. */ + std::string + name() const override + { + return "counting"; + } + + /** @brief Selects funds or reports a service error. @param request The selection request. @return Selected funds and change. */ + CoinSelectionResult + select(const CoinSelectionRequest& request) const override + { + ++calls; + + if (fail) + { + throw std::runtime_error("Test selection failure"); + } + + return LargeFirstCoinSelector().select(request); + } +}; + +/** @brief Next native allocation to fail. */ +std::size_t failureIndex = 0; +/** @brief Number of native allocations attempted. */ +std::size_t allocationIndex = 0; + +/** @brief Allocates or injects a failure. @param size The byte count. @return Memory or null. */ +void* +failingMalloc(std::size_t size) +{ + return allocationIndex++ == failureIndex ? nullptr : std::malloc(size); +} + +/** @brief Reallocates or injects a failure. @param pointer Existing memory. @param size The byte count. @return Memory or null. */ +void* +failingRealloc(void* pointer, std::size_t size) +{ + return allocationIndex++ == failureIndex ? nullptr : std::realloc(pointer, size); +} + +/** @brief Restores allocators after a failure injection. */ +class AllocationFailure +{ + public: + + /** @brief Selects a failing allocation. @param index The zero-based allocation index. */ + explicit AllocationFailure(std::size_t index) + { + failureIndex = index; + allocationIndex = 0; + cardano_set_allocators(failingMalloc, failingRealloc, std::free); + } + + /** @brief Restores the ordinary allocator. */ + ~AllocationFailure() + { + cardano_set_allocators(std::malloc, std::realloc, std::free); + } +}; + +/** @brief Dispatches an operation for allocation-failure cleanup checks. @param operation The operation index. @param transaction The immutable source. @param params The protocol parameters. @param utxos Available funds. */ +void +exercise(std::size_t operation, const Transaction& transaction, const ProtocolParameters& params, const UtxoList& utxos) +{ + switch (operation) + { + case 0: + (void)computeTransactionFee(transaction, utxos, params); + break; + case 1: + (void)computeMinAdaRequired(utxos.front().output(), 4310); + break; + case 2: + (void)computeImplicitCoin(transaction, params); + break; + case 3: + (void)computeTransactionImbalance(transaction, utxos, params); + break; + case 4: + (void)computeScriptDataHash(CostModels(), RedeemerList(), PlutusDataSet { PlutusData(BigInt(42)) }); + break; + case 5: + (void)totalExecutionUnits(RedeemerList { Redeemer(RedeemerTag::Spend, 0, PlutusData(BigInt(0)), ExUnits(10, 20)) }); + break; + case 6: + { + TransactionBalanceRequest request(transaction, params, address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + request.available = utxos; + request.coinSelector = std::make_shared(); + (void)balanceTransaction(request); + break; + } + default: + throw std::invalid_argument("Unknown test operation"); + } +} + +/** @brief Tests each public utility failure path under native allocation failure. */ +class UtilityAllocation : public testing::TestWithParam +{ +}; +} // namespace + +/* IMPLEMENTATION ************************************************************/ + +TEST(TransactionUtilities, PricesBytesWithoutChangingInputs) +{ + // Arrange + const Transaction transaction = draft(); + const TransactionOutput output = funding().output(); + const std::vector original = transaction.toCbor(); + + // Act & Assert + EXPECT_EQ(serializedTransactionSize(transaction), original.size()); + EXPECT_EQ(serializedOutputSize(output), output.toCbor().size()); + EXPECT_EQ(serializedCoinSize(23), 1U); + EXPECT_EQ(serializedCoinSize(24), 2U); + EXPECT_EQ(serializedCoinSize(256), 3U); + EXPECT_EQ(serializedCoinSize(std::numeric_limits::max()), 9U); + EXPECT_EQ(computeMinFeeWithoutScripts(transaction, 155381, 44), 155381U + 44U * (original.size() - 1)); + EXPECT_EQ(computeTransactionFee(transaction, {}, parameters()), computeMinFeeWithoutScripts(transaction, 155381, 44)); + EXPECT_EQ(computeMinAdaRequired(output, 4310), (160U + output.toCbor().size()) * 4310U); + EXPECT_EQ(transaction.toCbor(), original); +} + +TEST(TransactionUtilities, SumsBudgetsAndPricesExecution) +{ + // Arrange + const RedeemerList redeemers { + Redeemer(RedeemerTag::Spend, 0, PlutusData(BigInt(0)), ExUnits(10, 20)), + Redeemer(RedeemerTag::Mint, 0, PlutusData(BigInt(1)), ExUnits(30, 40)) + }; + Transaction transaction = draft(); + WitnessSet witnesses; + witnesses.setRedeemers(redeemers); + transaction.setWitnessSet(witnesses); + + // Act & Assert + EXPECT_EQ(totalExecutionUnits(redeemers), ExUnits(40, 60)); + EXPECT_EQ(totalExecutionUnits(RedeemerList()), ExUnits(0, 0)); + EXPECT_EQ(computeMinScriptFee(transaction, ExUnitPrices(UnitInterval(1, 2), UnitInterval(1, 4)), {}, UnitInterval(0, 1)), 35U); + EXPECT_EQ(computeTransactionFee(transaction, {}, parameters()), computeMinFeeWithoutScripts(transaction, 155381, 44) + 35U); +} + +TEST(TransactionUtilities, PricesReferenceScriptsAndCustomTiers) +{ + // Arrange + const PlutusV4Script plutus = PlutusV4Script::fromHex("450100002499"); + const Script script = plutus; + TransactionOutput output = funding().output(); + output.setScriptRef(script); + const Utxo reference(funding().input(), output); + ProtocolParameters params = parameters(); + params.setRefScriptCostStride(2); + params.setRefScriptCostMultiplier(UnitInterval(2, 1)); + + // Act & Assert + const std::size_t size = serializedScriptSize(script); + EXPECT_EQ(size, plutus.toBytes().size()); + EXPECT_EQ(computeScriptRefFee({ reference }, UnitInterval(2, 1)), size * 2U); + EXPECT_GT(computeScriptRefFee({ reference }, params), size * 2U); + EXPECT_EQ(computeScriptRefFee({}, params), 0U); + EXPECT_EQ(serializedScriptSize(ScriptInvalidBefore(100)), NativeScript(ScriptInvalidBefore(100)).toCbor().size()); +} + +TEST(TransactionUtilities, ComputesOptionalScriptDataCommitment) +{ + // Arrange + const PlutusDataSet datums { PlutusData(BigInt(42)) }; + std::vector preimage { 0xa0 }; + const std::vector encoded = datums.toCbor(); + preimage.insert(preimage.end(), encoded.begin(), encoded.end()); + preimage.push_back(0xa0); + + // Act + const std::optional hash = computeScriptDataHash(CostModels(), RedeemerList(), datums); + + // Assert + EXPECT_FALSE(computeScriptDataHash(CostModels(), RedeemerList(), PlutusDataSet())); + ASSERT_TRUE(hash); + EXPECT_EQ(*hash, Blake2bHash::compute(preimage, 32)); +} + +TEST(TransactionUtilities, RejectsExecutionBudgetOverflow) +{ + // Arrange + const std::uint64_t maximum = std::numeric_limits::max(); + const RedeemerList memoryOverflow { + Redeemer(RedeemerTag::Spend, 0, PlutusData(0), ExUnits(maximum, 0)), + Redeemer(RedeemerTag::Spend, 1, PlutusData(0), ExUnits(1, 0)) + }; + const RedeemerList stepsOverflow { + Redeemer(RedeemerTag::Spend, 0, PlutusData(0), ExUnits(0, maximum)), + Redeemer(RedeemerTag::Spend, 1, PlutusData(0), ExUnits(0, 1)) + }; + + // Act & Assert + EXPECT_THROW(totalExecutionUnits(memoryOverflow), Error); + EXPECT_THROW(totalExecutionUnits(stepsOverflow), Error); + EXPECT_EQ(totalExecutionUnits(RedeemerList()), ExUnits(0, 0)); +} + +TEST(TransactionUtilities, ReportsSurplusDeficitAndCertificateDeposits) +{ + // Arrange + const Utxo input = funding(); + TransactionBody body(TransactionInputSet { input.input() }, TransactionOutputList { TransactionOutput(address(), Value(7'000'000)) }, 1'000'000); + const Credential credential(CredentialType::KeyHash, Blake2bHash(std::vector(28, 3))); + body.setCertificates(CertificateSet { RegistrationCert(credential, 2'000'000) }); + Transaction transaction(body, WitnessSet()); + + // Act & Assert + EXPECT_EQ(computeImplicitCoin(transaction, parameters()).deposits, 2'000'000U); + EXPECT_TRUE(isTransactionBalanced(transaction, { input }, parameters())); + EXPECT_TRUE(computeTransactionImbalance(transaction, { input }, parameters()).isZero()); + body.setFee(2'000'000); + transaction.setBody(body); + EXPECT_EQ(computeTransactionImbalance(transaction, { input }, parameters()).coin(), -1'000'000); + EXPECT_FALSE(isTransactionBalanced(transaction, { input }, parameters())); + body.setFee(0); + transaction.setBody(body); + EXPECT_EQ(computeTransactionBatchImbalance(transaction, { input }, parameters()).coin(), 1'000'000); +} + +TEST(TransactionUtilities, PreservesSignedAssetAndLovelaceDeficits) +{ + // Arrange + const AssetId asset(Blake2bHash(std::vector(28, 4)), AssetName::fromString("Token")); + Value outputValue(11'000'000); + outputValue.addAsset(asset, 2); + const Utxo input = funding(); + const Transaction transaction(TransactionBody(TransactionInputSet { input.input() }, TransactionOutputList { TransactionOutput(address(), outputValue) }, 0), WitnessSet()); + Value expected(-1'000'000); + expected.addAsset(asset, -2); + + // Act + const Value imbalance = computeTransactionImbalance(transaction, { input }, parameters()); + + // Assert + EXPECT_EQ(imbalance, expected); +} + +TEST(TransactionUtilities, BalancesACopyWithDefaultAndInjectedServices) +{ + // Arrange + const Transaction original = draft(); + TransactionBalanceRequest request(original, parameters(), address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + request.available = { funding() }; + + // Act + const Transaction defaultResult = balanceTransaction(request); + request.coinSelector = std::make_shared(); + const std::shared_ptr evaluator = std::make_shared(); + request.evaluator = evaluator; + const Transaction injectedResult = balanceTransaction(request); + + // Assert + EXPECT_EQ(request.transaction.toCbor(), original.toCbor()); + EXPECT_TRUE(isTransactionBalanced(defaultResult, request.available, request.parameters)); + EXPECT_TRUE(isTransactionBalanced(injectedResult, request.available, request.parameters)); + EXPECT_GT(injectedResult.body().fee(), 0U); + EXPECT_EQ(injectedResult.body().inputs().size(), 1U); +} + +TEST(TransactionUtilities, PreservesMandatoryInputsAndRejectsMissingResolution) +{ + // Arrange + Transaction original = draft(); + TransactionBody body = original.body(); + body.setInputs(TransactionInputSet { funding().input() }); + original.setBody(body); + TransactionBalanceRequest request(original, parameters(), address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + + // Act & Assert + EXPECT_THROW(balanceTransaction(request), std::invalid_argument); + request.available = { funding(), funding(3) }; + const Transaction balanced = balanceTransaction(request); + EXPECT_TRUE(balanced.body().inputs().contains(funding().input())); + EXPECT_EQ(request.transaction, original); +} + +TEST(TransactionUtilities, RejectsInvalidSpendingRedeemerIndexWithoutChangingDraft) +{ + // Arrange + Transaction transaction = draft(); + WitnessSet witnesses; + witnesses.setRedeemers(RedeemerList { Redeemer(RedeemerTag::Spend, 99, PlutusData(BigInt(0)), ExUnits(1, 1)) }); + transaction.setWitnessSet(witnesses); + TransactionBalanceRequest request(transaction, parameters(), address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + request.available = { funding() }; + + // Act & Assert + EXPECT_THROW(balanceTransaction(request), std::invalid_argument); + EXPECT_EQ(request.transaction, transaction); +} + +TEST(TransactionUtilities, RejectsSignedDraftsAndPreservesInputsOnServiceFailure) +{ + // Arrange + const Transaction original = draft(); + TransactionBalanceRequest request(original, parameters(), address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + request.available = { funding() }; + const std::shared_ptr selector = std::make_shared(); + selector->fail = true; + request.coinSelector = selector; + + // Act & Assert + EXPECT_THROW(balanceTransaction(request), Error); + EXPECT_GT(selector->calls, 0U); + EXPECT_EQ(request.transaction, original); + + WitnessSet witnesses; + witnesses.setVkeys(VkeyWitnessSet { VkeyWitness(Ed25519PublicKey(std::vector(32, 1)), Ed25519Signature(std::vector(64, 2))) }); + request.transaction.setWitnessSet(witnesses); + const Transaction signedDraft = request.transaction; + + EXPECT_THROW(balanceTransaction(request), std::invalid_argument); + EXPECT_EQ(request.transaction, signedDraft); +} + +TEST(TransactionUtilities, ReindexesSpendingRedeemersAndUsesInjectedEvaluator) +{ + // Arrange + const PlutusV4Script script = PlutusV4Script::fromHex("450100002499"); + const Address scriptAddress = EnterpriseAddress(NetworkId::Testnet, Credential(CredentialType::ScriptHash, script.hash())); + const Utxo scriptInput(TransactionInput(Blake2bHash(std::vector(32, 5)), 0), TransactionOutput(scriptAddress, Value(2'000'000))); + Transaction transaction = draft(); + TransactionBody body = transaction.body(); + body.setInputs(TransactionInputSet { scriptInput.input() }); + transaction.setBody(body); + + WitnessSet witnesses; + witnesses.setPlutusV4Scripts(PlutusV4ScriptSet { script }); + witnesses.setRedeemers(RedeemerList { Redeemer(RedeemerTag::Spend, 0, PlutusData(BigInt(7)), ExUnits(10, 20)) }); + transaction.setWitnessSet(witnesses); + + ProtocolParameters params = parameters(); + params.setCollateralPercentage(150); + params.setMaxCollateralInputs(3); + CostModels models; + models.insert(CostModel(PlutusLanguageVersion::V4, std::vector(179, 0))); + params.setCostModels(models); + + TransactionBalanceRequest request(transaction, params, address(), SlotConfig::forNetwork(NetworkMagic::Preprod)); + request.preselected = { scriptInput }; + request.available = { funding() }; + request.collateral = { funding(9) }; + request.coinSelector = std::make_shared(); + const std::shared_ptr evaluator = std::make_shared(); + request.evaluator = evaluator; + + // Act + const Transaction balanced = balanceTransaction(request); + + // Assert + EXPECT_GT(evaluator->calls, 0U); + ASSERT_EQ(balanced.body().inputs().size(), 2U); + EXPECT_EQ(balanced.body().inputs().at(1), scriptInput.input()); + ASSERT_TRUE(balanced.witnessSet().redeemers()); + const Redeemer redeemer = balanced.witnessSet().redeemers()->at(0); + EXPECT_EQ(redeemer.index(), 1U); + EXPECT_EQ(redeemer.data(), PlutusData(BigInt(7))); + EXPECT_TRUE(isTransactionBalanced(balanced, { scriptInput, funding() }, params)); + EXPECT_EQ(request.transaction, transaction); +} + +TEST(TransactionUtilities, IncludesSubTransactionValueInBatchImbalance) +{ + // Arrange + const Utxo input = funding(); + const SubTransaction intent(SubTransactionBody(TransactionInputSet { input.input() }, TransactionOutputList { TransactionOutput(address(), Value(9'000'000)) }), WitnessSet()); + TransactionBody body(TransactionInputSet(), TransactionOutputList(), 1'000'000); + body.setSubTransactions(SubTransactionSet { intent }); + const Transaction transaction(body, WitnessSet()); + + // Act & Assert + EXPECT_EQ(computeTransactionImbalance(transaction, { input }, parameters()).coin(), -1'000'000); + EXPECT_EQ(computeSubTransactionImbalance(intent, { input }, parameters()).coin(), 1'000'000); + EXPECT_TRUE(computeTransactionBatchImbalance(transaction, { input }, parameters()).isZero()); +} + +TEST_P(UtilityAllocation, PreservesInputsAndReleasesPartialResults) +{ + // Arrange + const Transaction transaction = draft(); + const ProtocolParameters params = parameters(); + const UtxoList utxos { funding() }; + const std::vector original = transaction.toCbor(); + std::size_t allocations = 0; + + { + AllocationFailure track(std::numeric_limits::max()); + exercise(GetParam(), transaction, params, utxos); + allocations = allocationIndex; + } + + ASSERT_GT(allocations, 0U); + std::size_t failures = 0; + + // Act + for (std::size_t index = 0; index < allocations; ++index) + { + { + AllocationFailure fail(index); + try + { + exercise(GetParam(), transaction, params, utxos); + } + catch (const std::exception&) + { + ++failures; + } + } + + // Assert + EXPECT_EQ(transaction.toCbor(), original); + } + + EXPECT_GT(failures, 0U); +} + +INSTANTIATE_TEST_SUITE_P(Operations, UtilityAllocation, testing::Values(0U, 1U, 2U, 3U, 4U, 5U, 6U)); diff --git a/lib/tests/installed/PackageTest.cpp b/lib/tests/installed/PackageTest.cpp index a3a49244..4f27b306 100644 --- a/lib/tests/installed/PackageTest.cpp +++ b/lib/tests/installed/PackageTest.cpp @@ -809,6 +809,20 @@ main() return 1; } + const Cometa::Transaction pricedTransaction(transactionBody, Cometa::WitnessSet()); + const std::size_t encodedSize = pricedTransaction.toCbor().size(); + const std::uint64_t minimumFee = Cometa::computeMinFeeWithoutScripts(pricedTransaction, 100, 2); + + if (Cometa::serializedTransactionSize(pricedTransaction) != encodedSize || minimumFee != 100 + 2 * (encodedSize - 1)) + { + return 1; + } + + if (Cometa::computeScriptDataHash(Cometa::CostModels(), Cometa::RedeemerList(), Cometa::PlutusDataSet())) + { + return 1; + } + return name.toString() == "Cometa" && budget.cpuSteps() == 2 && version.major() == 12 && slots.unixTimeFromSlot(0) == 1666656000ULL ? 0 From c661fc656435429a8809d0c29bd81191b467991d Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Tue, 3 Nov 2026 23:07:31 +0800 Subject: [PATCH 2/4] refactor: simplify mandatory input resolution --- .../Balancing/TransactionBalancing.cpp | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp index edd2fec8..9a9b0d72 100644 --- a/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp +++ b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp @@ -127,36 +127,31 @@ balanceTransaction(const TransactionBalanceRequest& request) const TransactionInputSet inputs = request.transaction.body().inputs(); UtxoList selected = request.preselected; - for (const TransactionInput& input: inputs) + TransactionInputSet unresolved = inputs; + + for (const Utxo& utxo: selected) { - bool found = false; + unresolved.erase(utxo.input()); + } - for (const Utxo& utxo: selected) + for (const Utxo& utxo: request.available) + { + if (unresolved.empty()) { - if (utxo.input() == input) - { - found = true; - break; - } + break; } - if (!found) + if (unresolved.erase(utxo.input()) == 0) { - for (const Utxo& utxo: request.available) - { - if (utxo.input() == input) - { - selected.push_back(utxo); - found = true; - break; - } - } + continue; } - if (!found) - { - throw std::invalid_argument("An initial spending input is not resolved by preselected or available UTxOs"); - } + selected.push_back(utxo); + } + + if (!unresolved.empty()) + { + throw std::invalid_argument("An initial spending input is not resolved by preselected or available UTxOs"); } CardanoObject transaction( From b674a9f56687762265432235dd72fc5b6a5f9e42 Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Wed, 4 Nov 2026 08:03:21 +0800 Subject: [PATCH 3/4] refactor: replace access classes with specific friend functions --- CMakeLists.txt | 2 +- CODING_CONVENTIONS.md | 6 + .../ProtocolParams/ProtocolParameters.h | 43 +++- lib/src/ProtocolParams/ProtocolParameters.cpp | 29 +++ .../ProtocolParametersInterop.h | 47 ++++ lib/src/Providers/ProviderAdapter.cpp | 62 ++--- .../Balancing/ImplicitCoin.cpp | 5 +- .../Balancing/TransactionBalancing.cpp | 38 +-- .../CoinSelectorAdapter.cpp | 231 ++++++++---------- lib/src/TransactionBuilder/Fee.cpp | 14 +- ...yAccess.cpp => TransactionConversions.cpp} | 18 +- ...ilityAccess.h => TransactionConversions.h} | 37 +-- .../ProtocolParams/ProtocolParametersTest.cpp | 41 ++++ lib/tests/Providers/ProviderAdapterTest.cpp | 26 ++ 14 files changed, 367 insertions(+), 232 deletions(-) create mode 100644 lib/src/ProtocolParams/ProtocolParametersInterop.h rename lib/src/TransactionBuilder/{TransactionUtilityAccess.cpp => TransactionConversions.cpp} (85%) rename lib/src/TransactionBuilder/{TransactionUtilityAccess.h => TransactionConversions.h} (57%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92702b5e..4abb58bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,7 +198,7 @@ ADD_LIBRARY (cometa STATIC lib/src/KeyHandlers/SecureKeyHandler.cpp lib/src/Providers/ProviderAdapter.cpp lib/src/Providers/BlockfrostProvider.cpp - lib/src/TransactionBuilder/TransactionUtilityAccess.cpp + lib/src/TransactionBuilder/TransactionConversions.cpp lib/src/TransactionBuilder/Fee.cpp lib/src/TransactionBuilder/ScriptDataHash.cpp lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp diff --git a/CODING_CONVENTIONS.md b/CODING_CONVENTIONS.md index 82450dd3..929d2cf8 100644 --- a/CODING_CONVENTIONS.md +++ b/CODING_CONVENTIONS.md @@ -138,6 +138,12 @@ the successful result into its destination. Preserve cleanup on partial failures and leave the destination unchanged when copy assignment fails. Shared helpers should have narrow, descriptive names; keep them in private implementation files. +Grant private access to the specific functions that need it. Do not introduce +stateless access classes or static-method containers solely to bypass visibility. +Keep conversion functions private, name the values and conversion direction, and +make ownership explicit in their internal documentation. Retain classes for domain +objects, resource ownership, callback state, and other concrete responsibilities. + Use documented `ErrorCode` values and `Error` for operation failures instead of requiring callers to interpret integers or include C headers. Keep each enum in its own header. Verify C/C++ enum mappings in unit tests, rather than scattering diff --git a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h index 9879644d..5769a119 100644 --- a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h +++ b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,11 @@ struct cardano_protocol_parameters_t; namespace Cometa { -class ProviderAdapter; +class Transaction; +class SubTransaction; +class Value; +struct ImplicitCoin; +struct TransactionBalanceRequest; /** * @brief A snapshot of a network's ledger limits, fees, deposits, and governance settings. @@ -796,14 +801,38 @@ class ProtocolParameters private: - /** @brief Allows transaction utilities to read protocol parameters. */ - friend class TransactionUtilityAccess; + /** @brief Grants computeTransactionFee access to stored protocol parameters. */ + friend std::uint64_t computeTransactionFee(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); - /** @brief Allows the provider bridge to copy parameters into native calls. */ - friend class ProviderAdapter; + /** @brief Grants computeScriptRefFee access to stored protocol parameters. */ + friend std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const ProtocolParameters& parameters); - /** @brief Allows the coin selection bridge to copy parameters into native calls. */ - friend class CoinSelectorAdapter; + /** @brief Grants computeImplicitCoin access to stored protocol parameters. */ + friend ImplicitCoin computeImplicitCoin(const Transaction& transaction, const ProtocolParameters& parameters); + + /** @brief Grants computeImplicitCoin access to stored protocol parameters. */ + friend ImplicitCoin computeImplicitCoin(const SubTransaction& transaction, const ProtocolParameters& parameters); + + /** @brief Grants computeTransactionImbalance access to stored protocol parameters. */ + friend Value computeTransactionImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + + /** @brief Grants computeSubTransactionImbalance access to stored protocol parameters. */ + friend Value computeSubTransactionImbalance(const SubTransaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + + /** @brief Grants computeTransactionBatchImbalance access to stored protocol parameters. */ + friend Value computeTransactionBatchImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + + /** @brief Grants isTransactionBalanced access to stored protocol parameters. */ + friend bool isTransactionBalanced(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + + /** @brief Grants balanceTransaction access to stored protocol parameters. */ + friend Transaction balanceTransaction(const TransactionBalanceRequest& request); + + /** @brief Grants copyProtocolParametersToNative access to stored protocol parameters. */ + friend cardano_protocol_parameters_t* copyProtocolParametersToNative(const ProtocolParameters& parameters); + + /** @brief Grants copyProtocolParametersFromNative access to stored protocol parameters. */ + friend ProtocolParameters copyProtocolParametersFromNative(const cardano_protocol_parameters_t* parameters); /** @brief Allows transaction builders to retain protocol parameters. */ friend class TransactionBuilder; diff --git a/lib/src/ProtocolParams/ProtocolParameters.cpp b/lib/src/ProtocolParams/ProtocolParameters.cpp index 1f91c425..5ebc84b1 100644 --- a/lib/src/ProtocolParams/ProtocolParameters.cpp +++ b/lib/src/ProtocolParams/ProtocolParameters.cpp @@ -26,6 +26,7 @@ #include #include "../CardanoInterop.h" +#include "ProtocolParametersInterop.h" #include @@ -1315,6 +1316,34 @@ ProtocolParameters::checked() const /* FUNCTIONS IMPLEMENTATION **************************************************/ +cardano_protocol_parameters_t* +copyProtocolParametersToNative(const ProtocolParameters& parameters) +{ + cardano_protocol_parameters_t* value = nullptr; + const cardano_error_t status = cardano_protocol_parameters_deep_clone(parameters.checked(), &value); + CardanoObject owner(value); + + checkCardanoError(status, "Copy protocol parameters to native"); + + return owner.release(); +} + +ProtocolParameters +copyProtocolParametersFromNative(const cardano_protocol_parameters_t* parameters) +{ + ProtocolParameters result; + + cardano_protocol_parameters_t* value = nullptr; + const cardano_error_t status = cardano_protocol_parameters_deep_clone(parameters, &value); + CardanoObject owner(value); + + checkCardanoError(status, "Copy protocol parameters from native"); + cardano_protocol_parameters_unref(&result.m_value); + result.m_value = owner.release(); + + return result; +} + void swap(ProtocolParameters& lhs, ProtocolParameters& rhs) noexcept { diff --git a/lib/src/ProtocolParams/ProtocolParametersInterop.h b/lib/src/ProtocolParams/ProtocolParametersInterop.h new file mode 100644 index 00000000..12209f67 --- /dev/null +++ b/lib/src/ProtocolParams/ProtocolParametersInterop.h @@ -0,0 +1,47 @@ +/** + * @file ProtocolParametersInterop.h + * + * @brief Private protocol-parameter conversions. + * + * @author angel.castillo + * @date Nov 02, 2026 + * + * Copyright 2026 Biglup Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* INCLUDES ******************************************************************/ + +#include + +/* PROTOTYPES ****************************************************************/ + +namespace Cometa +{ +/** + * @brief Copies C++ protocol parameters for a native operation. + * @param parameters The parameters to copy. + * @return An owned native reference. + */ +cardano_protocol_parameters_t* copyProtocolParametersToNative(const ProtocolParameters& parameters); + +/** + * @brief Copies native protocol parameters for a C++ callback. + * @param parameters The borrowed parameters to copy. + * @return Independent C++ parameters. + */ +ProtocolParameters copyProtocolParametersFromNative(const cardano_protocol_parameters_t* parameters); +} // namespace Cometa diff --git a/lib/src/Providers/ProviderAdapter.cpp b/lib/src/Providers/ProviderAdapter.cpp index 87dca834..de76148b 100644 --- a/lib/src/Providers/ProviderAdapter.cpp +++ b/lib/src/Providers/ProviderAdapter.cpp @@ -26,6 +26,7 @@ #include "ProviderAdapter.h" #include "../CardanoInterop.h" +#include "../ProtocolParams/ProtocolParametersInterop.h" #include #include @@ -499,37 +500,38 @@ evaluateTransaction(cardano_provider_impl_t* implementation, cardano_transaction return providerError(implementation, "Provider evaluation failed"); } } -} // namespace -/** @brief Connects protocol-parameter copying to the C++ provider. */ -class ProviderAdapter +/** + * @brief Dispatches a protocol-parameter query. + * @param implementation The native provider implementation. + * @param output Receives independent parameters. + * @return The native status. + */ +cardano_error_t +getParameters(cardano_provider_impl_t* implementation, cardano_protocol_parameters_t** output) { - public: - - /** - * @brief Dispatches a protocol-parameter query. - * @param implementation The native provider implementation. - * @param output Receives independent parameters. - * @return The native status. - */ - static cardano_error_t - getParameters(cardano_provider_impl_t* implementation, cardano_protocol_parameters_t** output) - { - try - { - const ProtocolParameters parameters = providerOf(implementation).getParameters(); - return cardano_protocol_parameters_deep_clone(parameters.checked(), output); - } - catch (const std::exception& error) - { - return providerError(implementation, error.what()); - } - catch (...) - { - return providerError(implementation, "Provider parameters query failed"); - } - } -}; + try + { + const ProtocolParameters parameters = providerOf(implementation).getParameters(); + + *output = copyProtocolParametersToNative(parameters); + + return CARDANO_SUCCESS; + } + catch (const std::bad_alloc&) + { + return CARDANO_ERROR_MEMORY_ALLOCATION_FAILED; + } + catch (const std::exception& error) + { + return providerError(implementation, error.what()); + } + catch (...) + { + return providerError(implementation, "Provider parameters query failed"); + } +} +} // namespace /* FUNCTIONS IMPLEMENTATION **************************************************/ @@ -554,7 +556,7 @@ createProviderAdapter(std::shared_ptr provider) std::memcpy(implementation.name, name.data(), name.size()); implementation.network_magic = static_cast(network); implementation.context = context; - implementation.get_parameters = &ProviderAdapter::getParameters; + implementation.get_parameters = &getParameters; implementation.get_unspent_outputs = &getUnspentOutputs; implementation.get_rewards_balance = &getRewardsAvailable; implementation.get_unspent_outputs_with_asset = &getUnspentOutputsWithAsset; diff --git a/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp b/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp index 8a024763..f82e6974 100644 --- a/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp +++ b/lib/src/TransactionBuilder/Balancing/ImplicitCoin.cpp @@ -26,7 +26,6 @@ #include #include "../../CardanoInterop.h" -#include "../TransactionUtilityAccess.h" #include #include @@ -43,7 +42,7 @@ computeImplicitCoin(const Transaction& transaction, const ProtocolParameters& pa decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); cardano_implicit_coin_t result {}; - checkCardanoError(cardano_compute_implicit_coin(nativeTransaction.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeImplicitCoin"); + checkCardanoError(cardano_compute_implicit_coin(nativeTransaction.get(), parameters.checked(), &result), "computeImplicitCoin"); return ImplicitCoin { result.withdrawals, result.deposits, result.reclaim_deposits }; } @@ -55,7 +54,7 @@ computeImplicitCoin(const SubTransaction& transaction, const ProtocolParameters& decodeCbor(transaction.toCbor(), cardano_sub_transaction_from_cbor)); cardano_implicit_coin_t result {}; - checkCardanoError(cardano_compute_sub_transaction_implicit_coin(nativeTransaction.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeImplicitCoin"); + checkCardanoError(cardano_compute_sub_transaction_implicit_coin(nativeTransaction.get(), parameters.checked(), &result), "computeImplicitCoin"); return ImplicitCoin { result.withdrawals, result.deposits, result.reclaim_deposits }; } diff --git a/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp index 9a9b0d72..831f28ba 100644 --- a/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp +++ b/lib/src/TransactionBuilder/Balancing/TransactionBalancing.cpp @@ -29,8 +29,8 @@ #include "../../CardanoInterop.h" #include "../CoinSelectorAdapter.h" +#include "../TransactionConversions.h" #include "../TransactionEvaluatorAdapter.h" -#include "../TransactionUtilityAccess.h" #include #include @@ -56,15 +56,15 @@ computeTransactionImbalance(const Transaction& transaction, const UtxoList& reso { CardanoObject nativeTransaction( decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); cardano_value_t* result = nullptr; - const cardano_error_t status = cardano_compute_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + const cardano_error_t status = cardano_compute_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), parameters.checked(), &result); CardanoObject owner(result); checkCardanoError(status, "computeTransactionImbalance"); - return TransactionUtilityAccess::copyValue(owner.get()); + return copyValueFromNative(owner.get()); } Value @@ -72,15 +72,15 @@ computeSubTransactionImbalance(const SubTransaction& transaction, const UtxoList { CardanoObject nativeTransaction( decodeCbor(transaction.toCbor(), cardano_sub_transaction_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); cardano_value_t* result = nullptr; - const cardano_error_t status = cardano_compute_sub_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + const cardano_error_t status = cardano_compute_sub_transaction_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), parameters.checked(), &result); CardanoObject owner(result); checkCardanoError(status, "computeSubTransactionImbalance"); - return TransactionUtilityAccess::copyValue(owner.get()); + return copyValueFromNative(owner.get()); } Value @@ -88,15 +88,15 @@ computeTransactionBatchImbalance(const Transaction& transaction, const UtxoList& { CardanoObject nativeTransaction( decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); cardano_value_t* result = nullptr; - const cardano_error_t status = cardano_compute_transaction_batch_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result); + const cardano_error_t status = cardano_compute_transaction_batch_imbalance(nativeTransaction.get(), nativeResolvedInputs.get(), parameters.checked(), &result); CardanoObject owner(result); checkCardanoError(status, "computeTransactionBatchImbalance"); - return TransactionUtilityAccess::copyValue(owner.get()); + return copyValueFromNative(owner.get()); } bool @@ -104,10 +104,10 @@ isTransactionBalanced(const Transaction& transaction, const UtxoList& resolvedIn { CardanoObject nativeTransaction( decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); bool result {}; - checkCardanoError(cardano_is_transaction_balanced(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "isTransactionBalanced"); + checkCardanoError(cardano_is_transaction_balanced(nativeTransaction.get(), nativeResolvedInputs.get(), parameters.checked(), &result), "isTransactionBalanced"); return result; } @@ -156,13 +156,13 @@ balanceTransaction(const TransactionBalanceRequest& request) CardanoObject transaction( decodeCbor(request.transaction.toCbor(), cardano_transaction_from_cbor)); - CardanoObject preselected(copyUtilityUtxos(selected)); - CardanoObject available(copyUtilityUtxos(request.available)); - CardanoObject references(copyUtilityUtxos(request.referenceInputs)); - CardanoObject collateral(copyUtilityUtxos(request.collateral)); - CardanoObject change(copyUtilityAddress(request.changeAddress)); + CardanoObject preselected(copyUtxosToNative(selected)); + CardanoObject available(copyUtxosToNative(request.available)); + CardanoObject references(copyUtxosToNative(request.referenceInputs)); + CardanoObject collateral(copyUtxosToNative(request.collateral)); + CardanoObject change(copyAddressToNative(request.changeAddress)); CardanoObject collateralChange( - copyUtilityAddress(request.collateralChangeAddress ? *request.collateralChangeAddress : request.changeAddress)); + copyAddressToNative(request.collateralChangeAddress ? *request.collateralChangeAddress : request.changeAddress)); cardano_input_to_redeemer_map_t* mapValue = nullptr; const cardano_error_t mapStatus = cardano_input_to_redeemer_map_new(&mapValue); @@ -225,7 +225,7 @@ balanceTransaction(const TransactionBalanceRequest& request) cardano_transaction_clear_cbor_cache(transaction.get()); const cardano_error_t status = cardano_balance_transaction( - transaction.get(), request.foreignSignatureCount, TransactionUtilityAccess::parameters(request.parameters), references.get(), preselected.get(), inputRedeemers.get(), available.get(), nativeSelector.get(), change.get(), collateral.get(), collateralChange.get(), nativeEvaluator.get(), nullptr); + transaction.get(), request.foreignSignatureCount, request.parameters.checked(), references.get(), preselected.get(), inputRedeemers.get(), available.get(), nativeSelector.get(), change.get(), collateral.get(), collateralChange.get(), nativeEvaluator.get(), nullptr); checkCardanoError(status, "balanceTransaction"); cardano_transaction_clear_cbor_cache(transaction.get()); diff --git a/lib/src/TransactionBuilder/CoinSelectorAdapter.cpp b/lib/src/TransactionBuilder/CoinSelectorAdapter.cpp index b847acf0..29bed488 100644 --- a/lib/src/TransactionBuilder/CoinSelectorAdapter.cpp +++ b/lib/src/TransactionBuilder/CoinSelectorAdapter.cpp @@ -26,6 +26,7 @@ #include "CoinSelectorAdapter.h" #include "../CardanoInterop.h" +#include "../ProtocolParams/ProtocolParametersInterop.h" #include #include @@ -166,134 +167,68 @@ copyAddress(const cardano_address_t* value) checkCardanoError(cardano_address_to_bytes(value, bytes.data(), bytes.size()), "CoinSelector address"); return Address(bytes); } -} // namespace -/** @brief Bridges a C++ selection strategy to a native callback. */ -class CoinSelectorAdapter +/** + * @brief Runs a C++ strategy for a native request. + * @param implementation The native strategy. + * @param request The selection request. + * @param selected Receives the selected outputs. + * @param remaining Receives the remaining outputs. + * @param change Receives the change outputs. + * @return The native status. + */ +cardano_error_t +select( + cardano_coin_selector_impl_t* implementation, + const cardano_coin_selection_request_t* request, + cardano_utxo_list_t** selected, + cardano_utxo_list_t** remaining, + cardano_transaction_output_list_t** change) noexcept { - public: - - /** - * @brief Runs a native strategy with C++ request and result values. - * @param selector The borrowed native strategy. - * @param request The selection request. - * @return Independent C++ selection results. - */ - static CoinSelectionResult - selectWithNative(cardano_coin_selector_t* selector, const CoinSelectionRequest& request) - { - CardanoObject available(copyUtxos(request.available)); - CardanoObject preselected(copyUtxos(request.preselected)); - CardanoObject outputs( - copyOutputs(request.outputsToCover)); - - const std::vector targetBytes = request.target.toCbor(); - CardanoObject target( - decodeCbor(targetBytes, cardano_value_from_cbor)); - - const std::vector addressBytes = request.changeAddress.toBytes(); - cardano_address_t* addressValue = nullptr; - const cardano_error_t addressStatus = cardano_address_from_bytes(addressBytes.data(), addressBytes.size(), &addressValue); - CardanoObject address(addressValue); - checkCardanoError(addressStatus, "CoinSelector change address"); - - cardano_protocol_parameters_t* parametersValue = nullptr; - const cardano_error_t parameterStatus = cardano_protocol_parameters_deep_clone(request.parameters.checked(), ¶metersValue); - CardanoObject parameters(parametersValue); - checkCardanoError(parameterStatus, "CoinSelector parameters"); - - cardano_coin_selection_request_t nativeRequest {}; - nativeRequest.pre_selected_utxo = preselected.get(); - nativeRequest.available_utxo = available.get(); - nativeRequest.target = target.get(); - nativeRequest.outputs_to_cover = outputs.get(); - nativeRequest.change_address = address.get(); - nativeRequest.protocol_params = parameters.get(); - - cardano_utxo_list_t* selectedValue = nullptr; - cardano_utxo_list_t* remainingValue = nullptr; - cardano_transaction_output_list_t* changeValue = nullptr; - const cardano_error_t status = cardano_coin_selector_select( - selector, &nativeRequest, &selectedValue, &remainingValue, &changeValue); - - CardanoObject selected(selectedValue); - CardanoObject remaining(remainingValue); - CardanoObject change(changeValue); - - checkCardanoError(status, "CoinSelector select"); - - CoinSelectionResult result; - result.selected = copyUtxos(selected.get()); - result.remaining = copyUtxos(remaining.get()); - result.change = copyOutputs(change.get()); - return result; - } + try + { + ProtocolParameters parameters = copyProtocolParametersFromNative(request->protocol_params); - /** - * @brief Runs a C++ strategy for a native request. - * @param implementation The native strategy. - * @param request The selection request. - * @param selected Receives the selected outputs. - * @param remaining Receives the remaining outputs. - * @param change Receives the change outputs. - * @return The native status. - */ - static cardano_error_t - select( - cardano_coin_selector_impl_t* implementation, - const cardano_coin_selection_request_t* request, - cardano_utxo_list_t** selected, - cardano_utxo_list_t** remaining, - cardano_transaction_output_list_t** change) noexcept - { - try - { - ProtocolParameters parameters; - cardano_protocol_parameters_unref(¶meters.m_value); - checkCardanoError( - cardano_protocol_parameters_deep_clone(request->protocol_params, ¶meters.m_value), - "CoinSelector parameters"); - - const std::vector targetBytes = encodeCbor(request->target, cardano_value_to_cbor); - CoinSelectionRequest selectionRequest( - copyUtxos(request->available_utxo), - Value::fromCbor(targetBytes), - copyAddress(request->change_address), - std::move(parameters)); - - selectionRequest.preselected = copyUtxos(request->pre_selected_utxo); - selectionRequest.outputsToCover = copyOutputs(request->outputs_to_cover); - - const SelectorContext* context = static_cast(implementation->context); - const CoinSelectionResult result = context->selector->select(selectionRequest); - - CardanoObject selectedOwner(copyUtxos(result.selected)); - CardanoObject remainingOwner(copyUtxos(result.remaining)); - CardanoObject changeOwner( - copyOutputs(result.change)); - - *selected = selectedOwner.release(); - *remaining = remainingOwner.release(); - *change = changeOwner.release(); - - return CARDANO_SUCCESS; - } - catch (const std::bad_alloc&) - { - return CARDANO_ERROR_MEMORY_ALLOCATION_FAILED; - } - catch (const std::exception& error) - { - std::snprintf(implementation->error_message, sizeof(implementation->error_message), "%s", error.what()); - return CARDANO_ERROR_GENERIC; - } - catch (...) - { - std::snprintf(implementation->error_message, sizeof(implementation->error_message), "%s", "Coin selection failed"); - return CARDANO_ERROR_GENERIC; - } - } -}; + const std::vector targetBytes = encodeCbor(request->target, cardano_value_to_cbor); + CoinSelectionRequest selectionRequest( + copyUtxos(request->available_utxo), + Value::fromCbor(targetBytes), + copyAddress(request->change_address), + std::move(parameters)); + + selectionRequest.preselected = copyUtxos(request->pre_selected_utxo); + selectionRequest.outputsToCover = copyOutputs(request->outputs_to_cover); + + const SelectorContext* context = static_cast(implementation->context); + const CoinSelectionResult result = context->selector->select(selectionRequest); + + CardanoObject selectedOwner(copyUtxos(result.selected)); + CardanoObject remainingOwner(copyUtxos(result.remaining)); + CardanoObject changeOwner( + copyOutputs(result.change)); + + *selected = selectedOwner.release(); + *remaining = remainingOwner.release(); + *change = changeOwner.release(); + + return CARDANO_SUCCESS; + } + catch (const std::bad_alloc&) + { + return CARDANO_ERROR_MEMORY_ALLOCATION_FAILED; + } + catch (const std::exception& error) + { + std::snprintf(implementation->error_message, sizeof(implementation->error_message), "%s", error.what()); + return CARDANO_ERROR_GENERIC; + } + catch (...) + { + std::snprintf(implementation->error_message, sizeof(implementation->error_message), "%s", "Coin selection failed"); + return CARDANO_ERROR_GENERIC; + } +} +} // namespace /* FUNCTIONS IMPLEMENTATION **************************************************/ @@ -316,7 +251,7 @@ createCoinSelectorAdapter(std::shared_ptr selector) std::memcpy(implementation.name, name.data(), name.size()); implementation.context = context; - implementation.select = &CoinSelectorAdapter::select; + implementation.select = &select; cardano_coin_selector_t* value = nullptr; const cardano_error_t status = cardano_coin_selector_new(implementation, &value); @@ -337,6 +272,48 @@ selectWithNative(cardano_coin_selector_t* selector, const CoinSelectionRequest& throw std::invalid_argument("Native CoinSelector is required"); } - return CoinSelectorAdapter::selectWithNative(selector, request); + CardanoObject available(copyUtxos(request.available)); + CardanoObject preselected(copyUtxos(request.preselected)); + CardanoObject outputs( + copyOutputs(request.outputsToCover)); + + const std::vector targetBytes = request.target.toCbor(); + CardanoObject target( + decodeCbor(targetBytes, cardano_value_from_cbor)); + + const std::vector addressBytes = request.changeAddress.toBytes(); + cardano_address_t* addressValue = nullptr; + const cardano_error_t addressStatus = cardano_address_from_bytes(addressBytes.data(), addressBytes.size(), &addressValue); + CardanoObject address(addressValue); + checkCardanoError(addressStatus, "CoinSelector change address"); + + CardanoObject parameters(copyProtocolParametersToNative(request.parameters)); + + cardano_coin_selection_request_t nativeRequest {}; + nativeRequest.pre_selected_utxo = preselected.get(); + nativeRequest.available_utxo = available.get(); + nativeRequest.target = target.get(); + nativeRequest.outputs_to_cover = outputs.get(); + nativeRequest.change_address = address.get(); + nativeRequest.protocol_params = parameters.get(); + + cardano_utxo_list_t* selectedValue = nullptr; + cardano_utxo_list_t* remainingValue = nullptr; + cardano_transaction_output_list_t* changeValue = nullptr; + const cardano_error_t status = cardano_coin_selector_select( + selector, &nativeRequest, &selectedValue, &remainingValue, &changeValue); + + CardanoObject selected(selectedValue); + CardanoObject remaining(remainingValue); + CardanoObject change(changeValue); + + checkCardanoError(status, "CoinSelector select"); + + CoinSelectionResult result; + result.selected = copyUtxos(selected.get()); + result.remaining = copyUtxos(remaining.get()); + result.change = copyOutputs(change.get()); + return result; } + } // namespace Cometa diff --git a/lib/src/TransactionBuilder/Fee.cpp b/lib/src/TransactionBuilder/Fee.cpp index 348f12cd..daecb8a5 100644 --- a/lib/src/TransactionBuilder/Fee.cpp +++ b/lib/src/TransactionBuilder/Fee.cpp @@ -26,7 +26,7 @@ #include #include "../CardanoInterop.h" -#include "TransactionUtilityAccess.h" +#include "TransactionConversions.h" #include #include @@ -45,10 +45,10 @@ computeTransactionFee(const Transaction& transaction, const UtxoList& resolvedIn { CardanoObject nativeTransaction( decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); std::uint64_t result {}; - checkCardanoError(cardano_compute_transaction_fee(nativeTransaction.get(), nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeTransactionFee"); + checkCardanoError(cardano_compute_transaction_fee(nativeTransaction.get(), nativeResolvedInputs.get(), parameters.checked(), &result), "computeTransactionFee"); return result; } @@ -72,7 +72,7 @@ computeMinScriptFee(const Transaction& transaction, const ExUnitPrices& prices, decodeCbor(transaction.toCbor(), cardano_transaction_from_cbor)); CardanoObject nativePrices( decodeCbor(prices.toCbor(), cardano_ex_unit_prices_from_cbor)); - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); CardanoObject nativeCoinsPerRefScriptByte( decodeCbor(coinsPerRefScriptByte.toCbor(), cardano_unit_interval_from_cbor)); @@ -97,7 +97,7 @@ computeMinFeeWithoutScripts(const Transaction& transaction, std::uint64_t consta std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const UnitInterval& coinsPerRefScriptByte) { - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); CardanoObject nativeCoinsPerRefScriptByte( decodeCbor(coinsPerRefScriptByte.toCbor(), cardano_unit_interval_from_cbor)); @@ -110,10 +110,10 @@ computeScriptRefFee(const UtxoList& resolvedInputs, const UnitInterval& coinsPer std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const ProtocolParameters& parameters) { - CardanoObject nativeResolvedInputs(copyUtilityUtxos(resolvedInputs)); + CardanoObject nativeResolvedInputs(copyUtxosToNative(resolvedInputs)); std::uint64_t result {}; - checkCardanoError(cardano_compute_script_ref_fee_with_params(nativeResolvedInputs.get(), TransactionUtilityAccess::parameters(parameters), &result), "computeScriptRefFee"); + checkCardanoError(cardano_compute_script_ref_fee_with_params(nativeResolvedInputs.get(), parameters.checked(), &result), "computeScriptRefFee"); return result; } diff --git a/lib/src/TransactionBuilder/TransactionUtilityAccess.cpp b/lib/src/TransactionBuilder/TransactionConversions.cpp similarity index 85% rename from lib/src/TransactionBuilder/TransactionUtilityAccess.cpp rename to lib/src/TransactionBuilder/TransactionConversions.cpp index e6197e83..9f19a22d 100644 --- a/lib/src/TransactionBuilder/TransactionUtilityAccess.cpp +++ b/lib/src/TransactionBuilder/TransactionConversions.cpp @@ -1,7 +1,7 @@ /** - * @file TransactionUtilityAccess.cpp + * @file TransactionConversions.cpp * - * @brief Private parameter and UTxO conversion for transaction utilities. + * @brief Private transaction value and input conversions. * * @author angel.castillo * @date Nov 02, 2026 @@ -23,7 +23,7 @@ /* INCLUDES ******************************************************************/ -#include "TransactionUtilityAccess.h" +#include "TransactionConversions.h" #include "../CardanoInterop.h" #include @@ -36,14 +36,8 @@ namespace Cometa { -cardano_protocol_parameters_t* -TransactionUtilityAccess::parameters(const ProtocolParameters& parameters) -{ - return parameters.checked(); -} - Value -TransactionUtilityAccess::copyValue(cardano_value_t* value) +copyValueFromNative(cardano_value_t* value) { CardanoObject assets(cardano_value_get_multi_asset(value)); @@ -56,7 +50,7 @@ TransactionUtilityAccess::copyValue(cardano_value_t* value) } cardano_utxo_list_t* -copyUtilityUtxos(const UtxoList& utxos) +copyUtxosToNative(const UtxoList& utxos) { cardano_utxo_list_t* value = nullptr; const cardano_error_t status = cardano_utxo_list_new(&value); @@ -76,7 +70,7 @@ copyUtilityUtxos(const UtxoList& utxos) } cardano_address_t* -copyUtilityAddress(const Address& address) +copyAddressToNative(const Address& address) { const std::vector bytes = address.toBytes(); cardano_address_t* value = nullptr; diff --git a/lib/src/TransactionBuilder/TransactionUtilityAccess.h b/lib/src/TransactionBuilder/TransactionConversions.h similarity index 57% rename from lib/src/TransactionBuilder/TransactionUtilityAccess.h rename to lib/src/TransactionBuilder/TransactionConversions.h index b3cbd1e0..96943feb 100644 --- a/lib/src/TransactionBuilder/TransactionUtilityAccess.h +++ b/lib/src/TransactionBuilder/TransactionConversions.h @@ -1,7 +1,7 @@ /** - * @file TransactionUtilityAccess.h + * @file TransactionConversions.h * - * @brief Private access used by transaction utilities. + * @brief Private transaction value and input conversions. * * @author angel.castillo * @date Nov 02, 2026 @@ -27,51 +27,36 @@ #include #include -#include #include /* FORWARD DECLARATIONS ******************************************************/ -struct cardano_protocol_parameters_t; struct cardano_utxo_list_t; struct cardano_address_t; -/* DECLARATIONS **************************************************************/ +/* PROTOTYPES ****************************************************************/ namespace Cometa { -/** @brief Provides internal parameter access for transaction utilities. */ -class TransactionUtilityAccess -{ - public: - - /** - * @brief Gets the parameters borrowed for the duration of a utility call. - * @param parameters The owning C++ parameters. - * @return The borrowed native parameters. - */ - static cardano_protocol_parameters_t* parameters(const ProtocolParameters& parameters); - - /** - * @brief Copies a newly computed signed value. - * @param value The borrowed native value. - * @return The signed C++ value. - */ - static Value copyValue(cardano_value_t* value); -}; +/** + * @brief Copies a signed value without changing negative quantities. + * @param value The borrowed native value. + * @return An independent C++ value. + */ +Value copyValueFromNative(cardano_value_t* value); /** * @brief Copies resolved outputs into an owned native list. * @param utxos The outputs to copy. * @return The owned list. */ -cardano_utxo_list_t* copyUtilityUtxos(const UtxoList& utxos); +cardano_utxo_list_t* copyUtxosToNative(const UtxoList& utxos); /** * @brief Copies a change address into an owned native value. * @param address The address to copy. * @return The owned address. */ -cardano_address_t* copyUtilityAddress(const Address& address); +cardano_address_t* copyAddressToNative(const Address& address); } // namespace Cometa diff --git a/lib/tests/ProtocolParams/ProtocolParametersTest.cpp b/lib/tests/ProtocolParams/ProtocolParametersTest.cpp index 0cd42167..315774cb 100644 --- a/lib/tests/ProtocolParams/ProtocolParametersTest.cpp +++ b/lib/tests/ProtocolParams/ProtocolParametersTest.cpp @@ -25,9 +25,16 @@ #include +#include "../../src/CardanoInterop.h" +#include "../../src/ProtocolParams/ProtocolParametersInterop.h" + +#include + #include #include +#include +#include /* USINGS ********************************************************************/ @@ -198,3 +205,37 @@ TEST(ProtocolParameters, CopiesAndNullableFieldsAreIndependent) EXPECT_FALSE(parameters.perasBootstrapRound().has_value()); EXPECT_THROW(parameters.setMaxValueSize(std::numeric_limits::max()), std::out_of_range); } + +TEST(ProtocolParameters, InteropCopiesRemainIndependentInBothDirections) +{ + // Arrange + ProtocolParameters original; + original.setMinFeeA(44); + CardanoObject native(copyProtocolParametersToNative(original)); + + // Act + original.setMinFeeA(55); + ProtocolParameters copied = copyProtocolParametersFromNative(native.get()); + ASSERT_EQ(cardano_protocol_parameters_set_min_fee_a(native.get(), 66), CARDANO_SUCCESS); + + // Assert + EXPECT_EQ(original.minFeeA(), 55U); + EXPECT_EQ(copied.minFeeA(), 44U); + EXPECT_EQ(cardano_protocol_parameters_get_min_fee_a(native.get()), 66U); + + copied.setMinFeeA(77); + EXPECT_EQ(cardano_protocol_parameters_get_min_fee_a(native.get()), 66U); +} + +TEST(ProtocolParameters, InteropRejectsNullAndMovedFromSources) +{ + // Arrange + ProtocolParameters source; + ProtocolParameters empty(std::move(source)); + source.swap(empty); + + // Act & Assert + EXPECT_THROW(copyProtocolParametersFromNative(nullptr), Error); + EXPECT_THROW(copyProtocolParametersToNative(empty), std::logic_error); + EXPECT_EQ(source.minFeeA(), 0U); +} diff --git a/lib/tests/Providers/ProviderAdapterTest.cpp b/lib/tests/Providers/ProviderAdapterTest.cpp index 76b5a752..f3d36e71 100644 --- a/lib/tests/Providers/ProviderAdapterTest.cpp +++ b/lib/tests/Providers/ProviderAdapterTest.cpp @@ -45,6 +45,7 @@ #include #include +#include #include /* USINGS ********************************************************************/ @@ -73,6 +74,9 @@ class TestProvider : public Provider /** @brief Selects whether UTxO queries fail. */ bool failUtxos = false; + /** @brief Selects whether the parameter query exhausts memory. */ + bool failParametersAllocation = false; + /** @brief Gets the provider name. @return The name. */ std::string name() const override @@ -91,6 +95,11 @@ class TestProvider : public Provider ProtocolParameters getParameters() const override { + if (failParametersAllocation) + { + throw std::bad_alloc(); + } + ProtocolParameters parameters; parameters.setMinFeeA(44); return parameters; @@ -373,3 +382,20 @@ TEST(ProviderAdapter, EvaluatesThroughProviderStrategy) EXPECT_EQ(evaluator.name(), "test-provider"); EXPECT_EQ(result.size(), 0U); } + +TEST(ProviderAdapter, ReportsParameterAllocationFailures) +{ + // Arrange + const std::shared_ptr provider = std::make_shared(); + provider->failParametersAllocation = true; + CardanoObject native(createProviderAdapter(provider)); + cardano_protocol_parameters_t* parameters = nullptr; + + // Act + const cardano_error_t status = cardano_provider_get_parameters(native.get(), ¶meters); + CardanoObject owner(parameters); + + // Assert + EXPECT_EQ(status, CARDANO_ERROR_MEMORY_ALLOCATION_FAILED); + EXPECT_EQ(owner.get(), nullptr); +} From 4d8b4c6dc692107b4d89336138cd88fe5f072438 Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Wed, 4 Nov 2026 09:01:37 +0800 Subject: [PATCH 4/4] feat: add explicit native interoperability --- AGENTS.md | 2 +- CMakeLists.txt | 6 + CODING_CONVENTIONS.md | 25 +- doc/src/design.rst | 52 +++- lib/include/Cometa/Address/Address.h | 38 +-- lib/include/Cometa/Address/BaseAddress.h | 31 +++ lib/include/Cometa/Address/ByronAddress.h | 31 +++ .../Cometa/Address/EnterpriseAddress.h | 31 +++ lib/include/Cometa/Address/PointerAddress.h | 31 +++ lib/include/Cometa/Address/RewardAddress.h | 41 ++- lib/include/Cometa/Assets/AssetId.h | 34 ++- lib/include/Cometa/Assets/AssetIdMap.h | 39 +++ lib/include/Cometa/Assets/AssetName.h | 36 ++- lib/include/Cometa/Assets/AssetNameMap.h | 42 ++- lib/include/Cometa/Assets/MultiAsset.h | 48 +++- .../Cometa/AuxiliaryData/AuxiliaryData.h | 42 ++- lib/include/Cometa/AuxiliaryData/Metadatum.h | 36 ++- .../Cometa/AuxiliaryData/MetadatumList.h | 45 +++- .../Cometa/AuxiliaryData/MetadatumMap.h | 42 ++- .../Cometa/AuxiliaryData/PlutusV1ScriptList.h | 42 ++- .../Cometa/AuxiliaryData/PlutusV2ScriptList.h | 42 ++- .../Cometa/AuxiliaryData/PlutusV3ScriptList.h | 42 ++- .../Cometa/AuxiliaryData/PlutusV4ScriptList.h | 42 ++- .../AuxiliaryData/TransactionMetadata.h | 49 +++- lib/include/Cometa/Cbor/CborReader.h | 39 +++ lib/include/Cometa/Cbor/CborWriter.h | 39 +++ .../Certificates/AuthCommitteeHotCert.h | 36 ++- lib/include/Cometa/Certificates/Certificate.h | 37 ++- .../Cometa/Certificates/CertificateSet.h | 45 +++- .../Certificates/GenesisKeyDelegationCert.h | 36 ++- lib/include/Cometa/Certificates/MirCert.h | 34 ++- .../Cometa/Certificates/MirToPotCert.h | 36 ++- .../Certificates/MirToStakeCredentialsCert.h | 34 ++- .../Certificates/PoolRegistrationCert.h | 36 ++- .../Cometa/Certificates/PoolRetirementCert.h | 36 ++- .../Cometa/Certificates/RegisterDRepCert.h | 36 ++- .../Cometa/Certificates/RegistrationCert.h | 36 ++- .../Certificates/ResignCommitteeColdCert.h | 36 ++- .../Cometa/Certificates/StakeDelegationCert.h | 36 ++- .../Certificates/StakeDeregistrationCert.h | 36 ++- .../Certificates/StakeRegistrationCert.h | 36 ++- .../StakeRegistrationDelegationCert.h | 36 ++- .../Certificates/StakeVoteDelegationCert.h | 36 ++- .../StakeVoteRegistrationDelegationCert.h | 36 ++- .../Cometa/Certificates/UnregisterDRepCert.h | 36 ++- .../Cometa/Certificates/UnregistrationCert.h | 36 ++- .../Cometa/Certificates/UpdateDRepCert.h | 36 ++- .../Cometa/Certificates/VoteDelegationCert.h | 36 ++- .../VoteRegistrationDelegationCert.h | 36 ++- lib/include/Cometa/Common/Anchor.h | 47 ++-- lib/include/Cometa/Common/BigInt.h | 48 ++-- lib/include/Cometa/Common/Credential.h | 107 ++------ lib/include/Cometa/Common/CredentialSet.h | 42 ++- lib/include/Cometa/Common/DRep.h | 43 ++- lib/include/Cometa/Common/Datum.h | 34 ++- lib/include/Cometa/Common/ExUnits.h | 34 ++- .../Cometa/Common/GovernanceActionId.h | 41 ++- lib/include/Cometa/Common/ProtocolVersion.h | 34 ++- lib/include/Cometa/Common/UnitInterval.h | 45 ++-- lib/include/Cometa/Common/Utxo.h | 39 ++- lib/include/Cometa/Common/WithdrawalMap.h | 48 +++- lib/include/Cometa/Crypto/Bip32PrivateKey.h | 31 +++ lib/include/Cometa/Crypto/Bip32PublicKey.h | 32 ++- lib/include/Cometa/Crypto/Blake2bHash.h | 104 ++------ lib/include/Cometa/Crypto/Blake2bHashSet.h | 39 ++- lib/include/Cometa/Crypto/Ed25519PrivateKey.h | 32 ++- lib/include/Cometa/Crypto/Ed25519PublicKey.h | 33 ++- lib/include/Cometa/Crypto/Ed25519Signature.h | 33 ++- lib/include/Cometa/Json/JsonValue.h | 32 ++- lib/include/Cometa/Json/JsonWriter.h | 41 +++ .../Cometa/KeyHandlers/SecureKeyHandler.h | 16 ++ .../Cometa/PlutusData/ConstrPlutusData.h | 34 ++- lib/include/Cometa/PlutusData/PlutusData.h | 44 ++-- lib/include/Cometa/PlutusData/PlutusList.h | 60 +++-- lib/include/Cometa/PlutusData/PlutusMap.h | 42 ++- lib/include/Cometa/PoolParams/BlsKey.h | 34 ++- lib/include/Cometa/PoolParams/Ipv4.h | 34 ++- lib/include/Cometa/PoolParams/Ipv6.h | 34 ++- .../Cometa/PoolParams/MultiHostNameRelay.h | 34 ++- lib/include/Cometa/PoolParams/PoolMetadata.h | 34 ++- lib/include/Cometa/PoolParams/PoolOwners.h | 36 ++- lib/include/Cometa/PoolParams/PoolParams.h | 34 ++- lib/include/Cometa/PoolParams/Relay.h | 34 ++- lib/include/Cometa/PoolParams/Relays.h | 42 ++- .../Cometa/PoolParams/SingleHostAddrRelay.h | 34 ++- .../Cometa/PoolParams/SingleHostNameRelay.h | 34 ++- .../Cometa/ProposalProcedures/Committee.h | 31 +++ .../ProposalProcedures/CommitteeMembersMap.h | 42 ++- .../Cometa/ProposalProcedures/Constitution.h | 34 ++- .../HardForkInitiationAction.h | 34 ++- .../Cometa/ProposalProcedures/InfoAction.h | 34 ++- .../NewConstitutionAction.h | 34 ++- .../ProposalProcedures/NoConfidenceAction.h | 34 ++- .../ParameterChangeAction.h | 34 ++- .../ProposalProcedures/ProposalProcedure.h | 34 ++- .../ProposalProcedures/ProposalProcedureSet.h | 45 +++- .../TreasuryWithdrawalsAction.h | 34 ++- .../UpdateCommitteeAction.h | 34 ++- lib/include/Cometa/ProtocolParams/CostModel.h | 34 ++- .../Cometa/ProtocolParams/CostModels.h | 45 +++- .../ProtocolParams/DRepVotingThresholds.h | 33 ++- .../Cometa/ProtocolParams/ExUnitPrices.h | 33 ++- .../ProtocolParams/PoolVotingThresholds.h | 33 ++- .../ProtocolParams/ProposedParamUpdates.h | 33 ++- .../ProtocolParams/ProtocolParamUpdate.h | 33 ++- .../ProtocolParams/ProtocolParameters.h | 73 +++--- lib/include/Cometa/ProtocolParams/Update.h | 34 ++- .../Scripts/NativeScripts/NativeScript.h | 44 ++-- .../Scripts/NativeScripts/NativeScriptList.h | 62 +++-- .../Cometa/Scripts/NativeScripts/ScriptAll.h | 34 ++- .../Cometa/Scripts/NativeScripts/ScriptAny.h | 34 ++- .../NativeScripts/ScriptInvalidAfter.h | 34 ++- .../NativeScripts/ScriptInvalidBefore.h | 34 ++- .../Cometa/Scripts/NativeScripts/ScriptNOfK.h | 34 ++- .../Scripts/NativeScripts/ScriptPubkey.h | 34 ++- .../NativeScripts/ScriptRequireGuard.h | 34 ++- .../Scripts/PlutusScripts/PlutusV1Script.h | 36 ++- .../Scripts/PlutusScripts/PlutusV2Script.h | 36 ++- .../Scripts/PlutusScripts/PlutusV3Script.h | 36 ++- .../Scripts/PlutusScripts/PlutusV4Script.h | 36 ++- lib/include/Cometa/Scripts/Script.h | 40 ++- .../Cometa/Transaction/SubTransaction.h | 34 ++- .../Cometa/Transaction/SubTransactionSet.h | 36 ++- lib/include/Cometa/Transaction/Transaction.h | 31 +++ .../TransactionBody/AccountBalanceInterval.h | 34 ++- .../AccountBalanceIntervalsMap.h | 45 +++- .../Cometa/TransactionBody/DirectDepositMap.h | 45 +++- lib/include/Cometa/TransactionBody/GuardSet.h | 42 ++- .../TransactionBody/RequiredGuardsMap.h | 45 +++- .../TransactionBody/SubTransactionBody.h | 34 ++- .../Cometa/TransactionBody/TransactionBody.h | 34 ++- .../Cometa/TransactionBody/TransactionInput.h | 40 ++- .../TransactionBody/TransactionInputSet.h | 39 ++- .../TransactionBody/TransactionOutput.h | 41 ++- .../TransactionBody/TransactionOutputList.h | 52 +++- lib/include/Cometa/TransactionBody/Value.h | 34 ++- .../SubTransactionBuilder.h | 16 ++ .../TransactionBuilder/TransactionBuilder.h | 16 ++ lib/include/Cometa/VotingProcedures/Voter.h | 35 ++- .../Cometa/VotingProcedures/VotingProcedure.h | 34 ++- .../VotingProcedures/VotingProcedures.h | 45 +++- .../Cometa/WitnessSet/BootstrapWitness.h | 34 ++- .../Cometa/WitnessSet/BootstrapWitnessSet.h | 36 ++- .../Cometa/WitnessSet/NativeScriptSet.h | 36 ++- lib/include/Cometa/WitnessSet/PlutusDataSet.h | 36 ++- .../Cometa/WitnessSet/PlutusV1ScriptSet.h | 36 ++- .../Cometa/WitnessSet/PlutusV2ScriptSet.h | 36 ++- .../Cometa/WitnessSet/PlutusV3ScriptSet.h | 36 ++- .../Cometa/WitnessSet/PlutusV4ScriptSet.h | 36 ++- lib/include/Cometa/WitnessSet/Redeemer.h | 34 ++- lib/include/Cometa/WitnessSet/RedeemerList.h | 36 ++- lib/include/Cometa/WitnessSet/VkeyWitness.h | 34 ++- .../Cometa/WitnessSet/VkeyWitnessSet.h | 42 ++- lib/include/Cometa/WitnessSet/WitnessSet.h | 35 ++- lib/src/Address/Address.cpp | 31 +++ lib/src/Address/BaseAddress.cpp | 39 ++- lib/src/Address/ByronAddress.cpp | 37 ++- lib/src/Address/EnterpriseAddress.cpp | 37 ++- lib/src/Address/PointerAddress.cpp | 37 ++- lib/src/Address/RewardAddress.cpp | 37 ++- lib/src/Assets/AssetId.cpp | 37 ++- lib/src/Assets/AssetIdMap.cpp | 64 ++++- lib/src/Assets/AssetName.cpp | 31 +++ lib/src/Assets/AssetNameMap.cpp | 64 ++++- lib/src/Assets/MultiAsset.cpp | 68 ++++- lib/src/AuxiliaryData/AuxiliaryData.cpp | 68 +++-- lib/src/AuxiliaryData/Metadatum.cpp | 45 +++- lib/src/AuxiliaryData/MetadatumList.cpp | 60 ++++- lib/src/AuxiliaryData/MetadatumMap.cpp | 70 ++++- lib/src/AuxiliaryData/PlutusV1ScriptList.cpp | 60 ++++- lib/src/AuxiliaryData/PlutusV2ScriptList.cpp | 60 ++++- lib/src/AuxiliaryData/PlutusV3ScriptList.cpp | 60 ++++- lib/src/AuxiliaryData/PlutusV4ScriptList.cpp | 60 ++++- lib/src/AuxiliaryData/TransactionMetadata.cpp | 71 ++++- lib/src/CardanoInterop.h | 22 ++ lib/src/Cbor/CborReader.cpp | 38 ++- lib/src/Cbor/CborWriter.cpp | 38 ++- lib/src/Certificates/AuthCommitteeHotCert.cpp | 41 ++- lib/src/Certificates/Certificate.cpp | 143 ++++++---- lib/src/Certificates/CertificateSet.cpp | 60 ++++- .../Certificates/GenesisKeyDelegationCert.cpp | 45 +++- lib/src/Certificates/MirCert.cpp | 41 ++- lib/src/Certificates/MirToPotCert.cpp | 31 +++ .../MirToStakeCredentialsCert.cpp | 35 ++- lib/src/Certificates/PoolRegistrationCert.cpp | 37 ++- lib/src/Certificates/PoolRetirementCert.cpp | 37 ++- lib/src/Certificates/RegisterDRepCert.cpp | 39 ++- lib/src/Certificates/RegistrationCert.cpp | 37 ++- .../Certificates/ResignCommitteeColdCert.cpp | 39 ++- lib/src/Certificates/StakeDelegationCert.cpp | 41 ++- .../Certificates/StakeDeregistrationCert.cpp | 37 ++- .../Certificates/StakeRegistrationCert.cpp | 37 ++- .../StakeRegistrationDelegationCert.cpp | 41 ++- .../Certificates/StakeVoteDelegationCert.cpp | 45 +++- .../StakeVoteRegistrationDelegationCert.cpp | 45 +++- lib/src/Certificates/UnregisterDRepCert.cpp | 37 ++- lib/src/Certificates/UnregistrationCert.cpp | 37 ++- lib/src/Certificates/UpdateDRepCert.cpp | 39 ++- lib/src/Certificates/VoteDelegationCert.cpp | 41 ++- .../VoteRegistrationDelegationCert.cpp | 41 ++- lib/src/Common/Anchor.cpp | 31 +++ lib/src/Common/BigInt.cpp | 31 +++ lib/src/Common/Credential.cpp | 31 +++ lib/src/Common/CredentialSet.cpp | 43 ++- lib/src/Common/DRep.cpp | 37 ++- lib/src/Common/Datum.cpp | 35 ++- lib/src/Common/ExUnits.cpp | 31 +++ lib/src/Common/GovernanceActionId.cpp | 31 +++ lib/src/Common/ProtocolVersion.cpp | 31 +++ lib/src/Common/UnitInterval.cpp | 31 +++ lib/src/Common/Utxo.cpp | 50 +++- lib/src/Common/WithdrawalMap.cpp | 64 ++++- lib/src/Crypto/Bip32PrivateKey.cpp | 35 ++- lib/src/Crypto/Bip32PublicKey.cpp | 35 ++- lib/src/Crypto/Blake2bHash.cpp | 31 +++ lib/src/Crypto/Blake2bHashSet.cpp | 43 ++- lib/src/Crypto/Ed25519PrivateKey.cpp | 35 ++- lib/src/Crypto/Ed25519PublicKey.cpp | 35 ++- lib/src/Crypto/Ed25519Signature.cpp | 31 +++ lib/src/Json/JsonValue.cpp | 31 +++ lib/src/Json/JsonWriter.cpp | 46 +++- lib/src/KeyHandlers/SecureKeyHandler.cpp | 12 + lib/src/PlutusData/ConstrPlutusData.cpp | 37 ++- lib/src/PlutusData/PlutusData.cpp | 51 +++- lib/src/PlutusData/PlutusList.cpp | 60 ++++- lib/src/PlutusData/PlutusMap.cpp | 66 ++++- lib/src/PoolParams/BlsKey.cpp | 31 +++ lib/src/PoolParams/Ipv4.cpp | 31 +++ lib/src/PoolParams/Ipv6.cpp | 31 +++ lib/src/PoolParams/MultiHostNameRelay.cpp | 31 +++ lib/src/PoolParams/PoolMetadata.cpp | 37 ++- lib/src/PoolParams/PoolOwners.cpp | 43 ++- lib/src/PoolParams/PoolParams.cpp | 65 +++-- lib/src/PoolParams/Relay.cpp | 47 +++- lib/src/PoolParams/Relays.cpp | 60 ++++- lib/src/PoolParams/SingleHostAddrRelay.cpp | 37 ++- lib/src/PoolParams/SingleHostNameRelay.cpp | 31 +++ lib/src/ProposalProcedures/Committee.cpp | 47 +++- .../CommitteeMembersMap.cpp | 66 ++++- lib/src/ProposalProcedures/Constitution.cpp | 43 ++- .../HardForkInitiationAction.cpp | 43 ++- lib/src/ProposalProcedures/InfoAction.cpp | 31 +++ .../NewConstitutionAction.cpp | 43 ++- .../ProposalProcedures/NoConfidenceAction.cpp | 37 ++- .../ParameterChangeAction.cpp | 49 +++- .../ProposalProcedures/ProposalProcedure.cpp | 67 +++-- .../ProposalProcedureSet.cpp | 60 ++++- .../TreasuryWithdrawalsAction.cpp | 43 ++- .../UpdateCommitteeAction.cpp | 51 +++- lib/src/ProtocolParams/CostModel.cpp | 31 +++ lib/src/ProtocolParams/CostModels.cpp | 60 ++++- .../ProtocolParams/DRepVotingThresholds.cpp | 91 ++++--- lib/src/ProtocolParams/ExUnitPrices.cpp | 41 ++- .../ProtocolParams/PoolVotingThresholds.cpp | 61 +++-- .../ProtocolParams/ProposedParamUpdates.cpp | 45 +++- .../ProtocolParams/ProtocolParamUpdate.cpp | 109 +++++--- lib/src/ProtocolParams/ProtocolParameters.cpp | 121 +++++---- lib/src/ProtocolParams/Update.cpp | 37 ++- .../Scripts/NativeScripts/NativeScript.cpp | 86 ++++-- .../NativeScripts/NativeScriptList.cpp | 69 ++++- lib/src/Scripts/NativeScripts/ScriptAll.cpp | 40 ++- lib/src/Scripts/NativeScripts/ScriptAny.cpp | 40 ++- .../NativeScripts/ScriptInvalidAfter.cpp | 31 +++ .../NativeScripts/ScriptInvalidBefore.cpp | 31 +++ lib/src/Scripts/NativeScripts/ScriptNOfK.cpp | 40 ++- .../Scripts/NativeScripts/ScriptPubkey.cpp | 37 ++- .../NativeScripts/ScriptRequireGuard.cpp | 37 ++- .../Scripts/PlutusScripts/PlutusV1Script.cpp | 33 ++- .../Scripts/PlutusScripts/PlutusV2Script.cpp | 33 ++- .../Scripts/PlutusScripts/PlutusV3Script.cpp | 33 ++- .../Scripts/PlutusScripts/PlutusV4Script.cpp | 33 ++- lib/src/Scripts/Script.cpp | 68 +++-- lib/src/Transaction/SubTransaction.cpp | 49 +++- lib/src/Transaction/SubTransactionSet.cpp | 45 +++- lib/src/Transaction/Transaction.cpp | 67 +++-- .../AccountBalanceInterval.cpp | 31 +++ .../AccountBalanceIntervalsMap.cpp | 66 ++++- lib/src/TransactionBody/DirectDepositMap.cpp | 62 ++++- lib/src/TransactionBody/GuardSet.cpp | 41 ++- lib/src/TransactionBody/RequiredGuardsMap.cpp | 72 ++++- .../TransactionBody/SubTransactionBody.cpp | 91 ++++--- lib/src/TransactionBody/TransactionBody.cpp | 115 +++++--- lib/src/TransactionBody/TransactionInput.cpp | 44 +++- .../TransactionBody/TransactionInputSet.cpp | 43 ++- lib/src/TransactionBody/TransactionOutput.cpp | 62 +++-- .../TransactionBody/TransactionOutputList.cpp | 69 ++++- lib/src/TransactionBody/Value.cpp | 37 ++- .../Balancing/ImplicitCoin.cpp | 4 +- .../Balancing/TransactionBalancing.cpp | 10 +- lib/src/TransactionBuilder/Fee.cpp | 4 +- .../SubTransactionBuilder.cpp | 15 +- .../TransactionBuilder/TransactionBuilder.cpp | 15 +- lib/src/ValueValidation.h | 105 ++++++++ lib/src/VotingProcedures/Voter.cpp | 37 ++- lib/src/VotingProcedures/VotingProcedure.cpp | 37 ++- lib/src/VotingProcedures/VotingProcedures.cpp | 70 ++++- lib/src/WitnessSet/BootstrapWitness.cpp | 41 ++- lib/src/WitnessSet/BootstrapWitnessSet.cpp | 41 ++- lib/src/WitnessSet/NativeScriptSet.cpp | 41 ++- lib/src/WitnessSet/PlutusDataSet.cpp | 41 ++- lib/src/WitnessSet/PlutusV1ScriptSet.cpp | 41 ++- lib/src/WitnessSet/PlutusV2ScriptSet.cpp | 41 ++- lib/src/WitnessSet/PlutusV3ScriptSet.cpp | 41 ++- lib/src/WitnessSet/PlutusV4ScriptSet.cpp | 41 ++- lib/src/WitnessSet/Redeemer.cpp | 41 ++- lib/src/WitnessSet/RedeemerList.cpp | 41 ++- lib/src/WitnessSet/VkeyWitness.cpp | 43 ++- lib/src/WitnessSet/VkeyWitnessSet.cpp | 43 ++- lib/src/WitnessSet/WitnessSet.cpp | 69 +++-- lib/tests/Json/JsonWriterTest.cpp | 35 +++ .../KeyHandlers/SecureKeyHandlerTest.cpp | 16 ++ .../SubTransactionBuilderTest.cpp | 11 + .../TransactionBuilderTest.cpp | 11 + lib/tests/ValueContractTest.cpp | 248 ++++++++++++++++++ lib/tests/installed/PackageTest.cpp | 16 ++ 315 files changed, 11461 insertions(+), 1819 deletions(-) create mode 100644 lib/src/ValueValidation.h diff --git a/AGENTS.md b/AGENTS.md index 315dcd8c..d2c883bb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,7 +14,7 @@ section banners, access-group organization, Doxygen patterns, and CMake style. - Document private members and internal helpers as well as public declarations. - Keep API comments focused on their declaration and free of implementation details. - Use the checked-in `.clang-format` with clang-format 15. -- Keep native memory management private and automatic; preserve value semantics. +- Keep ordinary memory management automatic and preserve value semantics. Use the documented native interoperability methods for explicit C access. - Do not downgrade language features to match older reference projects. - Follow existing build, test, documentation, and package-consumer checks. - Keep style-only changes separate from behavioral changes. diff --git a/CMakeLists.txt b/CMakeLists.txt index 4abb58bf..bd44a1f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -787,6 +787,12 @@ INSTALL ( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +INSTALL ( + DIRECTORY "${cardano_source}/lib/include/cardano" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + INSTALL ( FILES "${cardano_archive}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cometa diff --git a/CODING_CONVENTIONS.md b/CODING_CONVENTIONS.md index 929d2cf8..36e593c8 100644 --- a/CODING_CONVENTIONS.md +++ b/CODING_CONVENTIONS.md @@ -109,9 +109,10 @@ Use separate access-label groups in this order, omitting groups that do not appl 3. Public static factories. 4. Public observers, modifiers, serialization, and swap. 5. Public assignment and comparison operators. -6. Private constructors used for internal ownership transfer. -7. Private helper methods. -8. Private data members. +6. Explicit native interoperability (adoption, borrowing, and release). +7. Private constructors used for internal ownership transfer. +8. Private helper methods. +9. Private data members. Repeat `public:` and `private:` to separate those groups. Keep blank lines after access labels and between documented declarations. Keep implementation order close @@ -127,7 +128,15 @@ without meaningful copy semantics may be noncopyable. Ordinary values use RAII and independent copy semantics; moves and swaps transfer ownership without allocating. Native C references may be owned privately by these RAII value classes. Temporary native allocations belong in scoped ownership guards. -Do not expose reference counting, disposal, or raw owning pointers in the public API. +Ordinary C++ operations must not require reference counting or disposal. Explicit +C interoperability is the exception: owning value wrappers provide `nativeHandle()`, +`release()`, and `adopt()` with documented borrowing and transfer contracts. +Reject null adoption; release leaves an empty object and returns null when already +empty. Provide const and mutable borrowed handles. Collections synchronize pending +iterator edits before borrowing or releasing, and mutable borrowing invalidates +C++ iterators and element references. These operations may throw when synchronization +is required. Resources retaining C++ callback state expose borrowing only unless +that state can safely accompany the native ownership transfer. When a C getter returns a shared reference, clone it before exposing a mutable value. Returning a named local by value may elide its copy; do not rely on that return statement to make the result independent. @@ -138,8 +147,9 @@ the successful result into its destination. Preserve cleanup on partial failures and leave the destination unchanged when copy assignment fails. Shared helpers should have narrow, descriptive names; keep them in private implementation files. -Grant private access to the specific functions that need it. Do not introduce -stateless access classes or static-method containers solely to bypass visibility. +Use the explicit native interoperability API instead of friendship for native access. +Do not introduce stateless access classes or static-method containers solely to +bypass visibility. Keep conversion functions private, name the values and conversion direction, and make ownership explicit in their internal documentation. Retain classes for domain objects, resource ownership, callback state, and other concrete responsibilities. @@ -212,7 +222,8 @@ void setHash(const Blake2bHash& hash); - Document only the declaration belonging to each comment; describe move behavior on move operations, not in the class summary. - Keep public documentation about observable behavior. Do not describe C handles, - reference counts, native storage, or cloning mechanisms in interface documentation. + reference counts, native storage, or cloning mechanisms in ordinary interface documentation. + Native interoperability methods must document pointer ownership, lifetime, and invalidation. - Use `@remark` only for useful behavior guarantees and important limits. - Distinguish owned return values from borrowed internal references. Describe mutation and moved-from behavior accurately. diff --git a/doc/src/design.rst b/doc/src/design.rst index 3f59c0e9..3ea2ee21 100644 --- a/doc/src/design.rst +++ b/doc/src/design.rst @@ -15,6 +15,56 @@ witness remains usable after its parent is destroyed. Collection accessors and iterators can return references; see :doc:`collections`. Mutating an object from multiple threads requires application-level synchronization. +C interoperability +------------------ + +Owning value wrappers expose three operations for integrating existing cardano-c +code: + +* ``nativeHandle()`` borrows a pointer. The const overload returns a pointer to + const. Do not unref a borrowed pointer or retain it beyond the next operation on + its C++ owner. +* ``release()`` transfers the owned reference and leaves the wrapper empty. The + caller must adopt it into another wrapper or call the matching C unref function. +* ``Type::adopt(pointer)`` takes ownership without copying or incrementing the + reference count. It rejects null with ``std::invalid_argument``. + +``JsonWriter::adopt(pointer, format)`` additionally requires the format used to +create the writer, so ``reset()`` preserves that choice. + +Borrowing or releasing an empty wrapper returns ``nullptr``. Empty wrappers can +be assigned, swapped, or destroyed; ordinary value operations reject them. + +.. code-block:: cpp + + #include + #include + + Cometa::AssetName name = Cometa::AssetName::fromString("Cometa"); + + cardano_asset_name_t* borrowed = name.nativeHandle(); + const std::size_t length = cardano_asset_name_get_bytes_size(borrowed); + + Cometa::AssetName transferred = Cometa::AssetName::adopt(name.release()); + +Collections synchronize edits through C++ element references before exposing a +native pointer. Synchronization can allocate and throw; on failure, ownership and +pending edits remain with the collection. A mutable borrow invalidates all C++ +iterators and element references. Finish native access before using C++ collection +operations again. Do not retain native pointers across later C++ operations or +mutate through a pointer obtained from a const wrapper. + +``TransactionBuilder``, ``SubTransactionBuilder``, and ``SecureKeyHandler`` expose +borrowed handles only: their C++ callback state cannot be transferred by a raw +pointer. Keep these wrappers alive during native calls. Use C++ signing methods +when a software signer needs its C++ passphrase provider; direct C calls do not +activate that provider. + +Use the matching cardano-c headers and library shipped with Cometa. Do not mix +objects from different cardano-c builds or change global allocators while native +objects are alive. Native mutations must respect cardano-c's invariants and any +required parent CBOR-cache invalidation. + Concrete and general values --------------------------- @@ -99,7 +149,7 @@ The project key is supplied at runtime. Distribution ------------ -Each platform ZIP contains the C++ headers, static and shared Cometa libraries, +Each platform ZIP contains the C++ and matching C headers, static and shared Cometa libraries, the static cardano-c archive, licenses, and a relocatable CMake package. The shared Cometa library includes cardano-c. The HTTP transport is available in both link modes. Windows uses the system WinHTTP service. Unix packages use diff --git a/lib/include/Cometa/Address/Address.h b/lib/include/Cometa/Address/Address.h index 384d0a23..543aeeff 100644 --- a/lib/include/Cometa/Address/Address.h +++ b/lib/include/Cometa/Address/Address.h @@ -268,38 +268,38 @@ class Address */ bool operator!=(const Address& other) const; - private: - - /** @brief Allows transactions to use this value. */ - friend class Transaction; - - /** @brief Allows TransactionOutput to copy components. */ - friend class TransactionOutput; + public: /** - * @brief Allows BaseAddress conversions to inspect this address. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - friend class BaseAddress; + static Address adopt(cardano_address_t* value); /** - * @brief Allows EnterpriseAddress conversions to inspect this address. + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. */ - friend class EnterpriseAddress; + cardano_address_t* nativeHandle() noexcept; /** - * @brief Allows RewardAddress conversions to inspect this address. + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. */ - friend class RewardAddress; + const cardano_address_t* nativeHandle() const noexcept; /** - * @brief Allows PointerAddress conversions to inspect this address. + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. */ - friend class PointerAddress; + cardano_address_t* release() noexcept; - /** - * @brief Allows ByronAddress conversions to inspect this address. - */ - friend class ByronAddress; + private: /** * @brief Adopts an owned native address. diff --git a/lib/include/Cometa/Address/BaseAddress.h b/lib/include/Cometa/Address/BaseAddress.h index 3371e169..4c5dc761 100644 --- a/lib/include/Cometa/Address/BaseAddress.h +++ b/lib/include/Cometa/Address/BaseAddress.h @@ -228,6 +228,37 @@ class BaseAddress */ bool operator!=(const BaseAddress& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static BaseAddress adopt(cardano_base_address_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_base_address_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_base_address_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_base_address_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Address/ByronAddress.h b/lib/include/Cometa/Address/ByronAddress.h index 33e23a33..c3c8d586 100644 --- a/lib/include/Cometa/Address/ByronAddress.h +++ b/lib/include/Cometa/Address/ByronAddress.h @@ -217,6 +217,37 @@ class ByronAddress */ bool operator!=(const ByronAddress& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ByronAddress adopt(cardano_byron_address_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_byron_address_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_byron_address_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_byron_address_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Address/EnterpriseAddress.h b/lib/include/Cometa/Address/EnterpriseAddress.h index 978074d6..391f3b2b 100644 --- a/lib/include/Cometa/Address/EnterpriseAddress.h +++ b/lib/include/Cometa/Address/EnterpriseAddress.h @@ -201,6 +201,37 @@ class EnterpriseAddress */ bool operator!=(const EnterpriseAddress& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static EnterpriseAddress adopt(cardano_enterprise_address_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_enterprise_address_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_enterprise_address_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_enterprise_address_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Address/PointerAddress.h b/lib/include/Cometa/Address/PointerAddress.h index 6c33d48b..eea521be 100644 --- a/lib/include/Cometa/Address/PointerAddress.h +++ b/lib/include/Cometa/Address/PointerAddress.h @@ -210,6 +210,37 @@ class PointerAddress */ bool operator!=(const PointerAddress& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PointerAddress adopt(cardano_pointer_address_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pointer_address_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pointer_address_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pointer_address_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Address/RewardAddress.h b/lib/include/Cometa/Address/RewardAddress.h index f58dda26..8ca83f57 100644 --- a/lib/include/Cometa/Address/RewardAddress.h +++ b/lib/include/Cometa/Address/RewardAddress.h @@ -201,25 +201,38 @@ class RewardAddress */ bool operator!=(const RewardAddress& other) const; - private: - - /** @brief Allows transactions to use this value. */ - friend class Transaction; + public: - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static RewardAddress adopt(cardano_reward_address_t* value); - /** @brief Allows PoolParams to copy pool components. */ - friend class PoolParams; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_reward_address_t* nativeHandle() noexcept; - /** @brief Allows WithdrawalMap to copy reward addresses. */ - friend class WithdrawalMap; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_reward_address_t* nativeHandle() const noexcept; - /** @brief Allows account balance maps to copy addresses. */ - friend class AccountBalanceIntervalsMap; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_reward_address_t* release() noexcept; - /** @brief Allows direct deposit maps to copy addresses. */ - friend class DirectDepositMap; + private: /** * @brief Adopts an owned native address. diff --git a/lib/include/Cometa/Assets/AssetId.h b/lib/include/Cometa/Assets/AssetId.h index 85c0b6b4..2bd869fa 100644 --- a/lib/include/Cometa/Assets/AssetId.h +++ b/lib/include/Cometa/Assets/AssetId.h @@ -202,10 +202,38 @@ class AssetId */ bool operator<(const AssetId& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AssetId adopt(cardano_asset_id_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_asset_id_t* nativeHandle() noexcept; - /** @brief Allows AssetIdMap to copy map keys. */ - friend class AssetIdMap; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_asset_id_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_asset_id_t* release() noexcept; + + private: /** * @brief Adopts one owned native identifier. diff --git a/lib/include/Cometa/Assets/AssetIdMap.h b/lib/include/Cometa/Assets/AssetIdMap.h index 39ba1a74..b3beb58b 100644 --- a/lib/include/Cometa/Assets/AssetIdMap.h +++ b/lib/include/Cometa/Assets/AssetIdMap.h @@ -500,6 +500,45 @@ class AssetIdMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AssetIdMap adopt(cardano_asset_id_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_asset_id_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_asset_id_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_asset_id_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ diff --git a/lib/include/Cometa/Assets/AssetName.h b/lib/include/Cometa/Assets/AssetName.h index 0c5ee984..0e41f041 100644 --- a/lib/include/Cometa/Assets/AssetName.h +++ b/lib/include/Cometa/Assets/AssetName.h @@ -229,16 +229,38 @@ class AssetName */ bool operator<(const AssetName& other) const; - private: + public: - /** @brief Allows MultiAsset to copy policy components. */ - friend class MultiAsset; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AssetName adopt(cardano_asset_name_t* value); - /** @brief Allows AssetNameMap to copy map keys. */ - friend class AssetNameMap; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_asset_name_t* nativeHandle() noexcept; - /** @brief Allows AssetId to copy identifier components. */ - friend class AssetId; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_asset_name_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_asset_name_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing value. diff --git a/lib/include/Cometa/Assets/AssetNameMap.h b/lib/include/Cometa/Assets/AssetNameMap.h index 0314b694..7153e35f 100644 --- a/lib/include/Cometa/Assets/AssetNameMap.h +++ b/lib/include/Cometa/Assets/AssetNameMap.h @@ -547,6 +547,45 @@ class AssetNameMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AssetNameMap adopt(cardano_asset_name_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_asset_name_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_asset_name_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_asset_name_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -574,9 +613,6 @@ class AssetNameMap private: - /** @brief Allows MultiAsset to copy policy maps. */ - friend class MultiAsset; - /** * @brief Adopts one owned native map. * diff --git a/lib/include/Cometa/Assets/MultiAsset.h b/lib/include/Cometa/Assets/MultiAsset.h index fa2292f6..c266d5a4 100644 --- a/lib/include/Cometa/Assets/MultiAsset.h +++ b/lib/include/Cometa/Assets/MultiAsset.h @@ -611,6 +611,45 @@ class MultiAsset } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MultiAsset adopt(cardano_multi_asset_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_multi_asset_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_multi_asset_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_multi_asset_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -638,15 +677,6 @@ class MultiAsset private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - - /** @brief Allows Value to copy its token quantities. */ - friend class Value; - /** * @brief Adopts one owned native collection. * diff --git a/lib/include/Cometa/AuxiliaryData/AuxiliaryData.h b/lib/include/Cometa/AuxiliaryData/AuxiliaryData.h index 29a977c1..1a4fa36e 100644 --- a/lib/include/Cometa/AuxiliaryData/AuxiliaryData.h +++ b/lib/include/Cometa/AuxiliaryData/AuxiliaryData.h @@ -263,13 +263,38 @@ class AuxiliaryData */ bool operator!=(const AuxiliaryData& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AuxiliaryData adopt(cardano_auxiliary_data_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_auxiliary_data_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_auxiliary_data_t* nativeHandle() const noexcept; - /** @brief Allows sub-transactions to copy this value. */ - friend class SubTransaction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_auxiliary_data_t* release() noexcept; - /** @brief Allows transactions to copy this value. */ - friend class Transaction; + private: /** * @brief Takes ownership of an existing reference. @@ -289,13 +314,6 @@ class AuxiliaryData */ cardano_auxiliary_data_t* checked() const; - /** - * @brief Validates decoded metadata labels and native scripts. - * - * @throws std::invalid_argument A nested value is invalid. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/AuxiliaryData/Metadatum.h b/lib/include/Cometa/AuxiliaryData/Metadatum.h index f8a70839..b77d1972 100644 --- a/lib/include/Cometa/AuxiliaryData/Metadatum.h +++ b/lib/include/Cometa/AuxiliaryData/Metadatum.h @@ -303,16 +303,38 @@ class Metadatum */ bool operator!=(const Metadatum& other) const; - private: + public: - /** @brief Allows MetadatumList to copy components. */ - friend class MetadatumList; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Metadatum adopt(cardano_metadatum_t* value); - /** @brief Allows MetadatumMap to copy components. */ - friend class MetadatumMap; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_metadatum_t* nativeHandle() noexcept; - /** @brief Allows TransactionMetadata to copy components. */ - friend class TransactionMetadata; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_metadatum_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_metadatum_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/AuxiliaryData/MetadatumList.h b/lib/include/Cometa/AuxiliaryData/MetadatumList.h index ae8ff702..e45f3f06 100644 --- a/lib/include/Cometa/AuxiliaryData/MetadatumList.h +++ b/lib/include/Cometa/AuxiliaryData/MetadatumList.h @@ -510,6 +510,45 @@ class MetadatumList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MetadatumList adopt(cardano_metadatum_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_metadatum_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_metadatum_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_metadatum_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -527,12 +566,6 @@ class MetadatumList private: - /** @brief Allows Metadatum to copy components. */ - friend class Metadatum; - - /** @brief Allows MetadatumMap to copy components. */ - friend class MetadatumMap; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/MetadatumMap.h b/lib/include/Cometa/AuxiliaryData/MetadatumMap.h index fe8da4ec..9a46ca5c 100644 --- a/lib/include/Cometa/AuxiliaryData/MetadatumMap.h +++ b/lib/include/Cometa/AuxiliaryData/MetadatumMap.h @@ -556,6 +556,45 @@ class MetadatumMap m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MetadatumMap adopt(cardano_metadatum_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_metadatum_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_metadatum_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_metadatum_map_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -573,9 +612,6 @@ class MetadatumMap private: - /** @brief Allows Metadatum to copy components. */ - friend class Metadatum; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/PlutusV1ScriptList.h b/lib/include/Cometa/AuxiliaryData/PlutusV1ScriptList.h index beca5d0c..3d309e14 100644 --- a/lib/include/Cometa/AuxiliaryData/PlutusV1ScriptList.h +++ b/lib/include/Cometa/AuxiliaryData/PlutusV1ScriptList.h @@ -509,6 +509,45 @@ class PlutusV1ScriptList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV1ScriptList adopt(cardano_plutus_v1_script_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v1_script_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_v1_script_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v1_script_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,9 +565,6 @@ class PlutusV1ScriptList private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/PlutusV2ScriptList.h b/lib/include/Cometa/AuxiliaryData/PlutusV2ScriptList.h index 43c66c58..b5d8e970 100644 --- a/lib/include/Cometa/AuxiliaryData/PlutusV2ScriptList.h +++ b/lib/include/Cometa/AuxiliaryData/PlutusV2ScriptList.h @@ -509,6 +509,45 @@ class PlutusV2ScriptList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV2ScriptList adopt(cardano_plutus_v2_script_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v2_script_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_v2_script_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v2_script_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,9 +565,6 @@ class PlutusV2ScriptList private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/PlutusV3ScriptList.h b/lib/include/Cometa/AuxiliaryData/PlutusV3ScriptList.h index 56168e1a..d2f5bbde 100644 --- a/lib/include/Cometa/AuxiliaryData/PlutusV3ScriptList.h +++ b/lib/include/Cometa/AuxiliaryData/PlutusV3ScriptList.h @@ -509,6 +509,45 @@ class PlutusV3ScriptList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV3ScriptList adopt(cardano_plutus_v3_script_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v3_script_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_v3_script_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v3_script_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,9 +565,6 @@ class PlutusV3ScriptList private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/PlutusV4ScriptList.h b/lib/include/Cometa/AuxiliaryData/PlutusV4ScriptList.h index 8fda6c98..2005d587 100644 --- a/lib/include/Cometa/AuxiliaryData/PlutusV4ScriptList.h +++ b/lib/include/Cometa/AuxiliaryData/PlutusV4ScriptList.h @@ -509,6 +509,45 @@ class PlutusV4ScriptList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV4ScriptList adopt(cardano_plutus_v4_script_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v4_script_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_v4_script_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_v4_script_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,9 +565,6 @@ class PlutusV4ScriptList private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/AuxiliaryData/TransactionMetadata.h b/lib/include/Cometa/AuxiliaryData/TransactionMetadata.h index 27fc4623..af0d369d 100644 --- a/lib/include/Cometa/AuxiliaryData/TransactionMetadata.h +++ b/lib/include/Cometa/AuxiliaryData/TransactionMetadata.h @@ -505,6 +505,45 @@ class TransactionMetadata } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionMetadata adopt(cardano_transaction_metadata_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_transaction_metadata_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_transaction_metadata_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_transaction_metadata_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -532,9 +571,6 @@ class TransactionMetadata private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - /** * @brief Takes ownership of an existing reference. * @@ -553,13 +589,6 @@ class TransactionMetadata */ cardano_transaction_metadata_t* checked() const; - /** - * @brief Rejects duplicate labels in decoded metadata. - * - * @throws std::invalid_argument A label occurs more than once. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/Cbor/CborReader.h b/lib/include/Cometa/Cbor/CborReader.h index 64985913..c56e6302 100644 --- a/lib/include/Cometa/Cbor/CborReader.h +++ b/lib/include/Cometa/Cbor/CborReader.h @@ -235,6 +235,45 @@ class CborReader */ CborReader& operator=(CborReader&& other) noexcept; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CborReader adopt(cardano_cbor_reader_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_cbor_reader_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_cbor_reader_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_cbor_reader_t* release() noexcept; + + private: + + /** + * @brief Takes ownership of a validated native reference. + * @param value The owned non-null reference. + */ + explicit CborReader(cardano_cbor_reader_t* value) noexcept; + private: /** diff --git a/lib/include/Cometa/Cbor/CborWriter.h b/lib/include/Cometa/Cbor/CborWriter.h index 70fbf12e..f3986a83 100644 --- a/lib/include/Cometa/Cbor/CborWriter.h +++ b/lib/include/Cometa/Cbor/CborWriter.h @@ -207,6 +207,45 @@ class CborWriter */ CborWriter& operator=(CborWriter&& other) noexcept; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CborWriter adopt(cardano_cbor_writer_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_cbor_writer_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_cbor_writer_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_cbor_writer_t* release() noexcept; + + private: + + /** + * @brief Takes ownership of a validated native reference. + * @param value The owned non-null reference. + */ + explicit CborWriter(cardano_cbor_writer_t* value) noexcept; + private: /** diff --git a/lib/include/Cometa/Certificates/AuthCommitteeHotCert.h b/lib/include/Cometa/Certificates/AuthCommitteeHotCert.h index 2c07cf1c..61960f00 100644 --- a/lib/include/Cometa/Certificates/AuthCommitteeHotCert.h +++ b/lib/include/Cometa/Certificates/AuthCommitteeHotCert.h @@ -186,6 +186,37 @@ class AuthCommitteeHotCert */ bool operator!=(const AuthCommitteeHotCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AuthCommitteeHotCert adopt(cardano_auth_committee_hot_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_auth_committee_hot_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_auth_committee_hot_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_auth_committee_hot_cert_t* release() noexcept; + private: /** @@ -202,11 +233,6 @@ class AuthCommitteeHotCert */ cardano_auth_committee_hot_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/Certificate.h b/lib/include/Cometa/Certificates/Certificate.h index 50fe5112..8f611973 100644 --- a/lib/include/Cometa/Certificates/Certificate.h +++ b/lib/include/Cometa/Certificates/Certificate.h @@ -529,10 +529,38 @@ class Certificate */ bool operator!=(const Certificate& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Certificate adopt(cardano_certificate_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_certificate_t* nativeHandle() noexcept; - /** @brief Allows transactions to use this value. */ - friend class Transaction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_certificate_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_certificate_t* release() noexcept; + + private: /** * @brief Adopts an owned certificate. @@ -546,9 +574,6 @@ class Certificate */ cardano_certificate_t* checked() const; - /** @brief Allows certificate collections to copy native values. */ - friend class CertificateSet; - private: /** @brief The owned certificate. */ diff --git a/lib/include/Cometa/Certificates/CertificateSet.h b/lib/include/Cometa/Certificates/CertificateSet.h index a85df358..e9559e6f 100644 --- a/lib/include/Cometa/Certificates/CertificateSet.h +++ b/lib/include/Cometa/Certificates/CertificateSet.h @@ -478,6 +478,45 @@ class CertificateSet m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CertificateSet adopt(cardano_certificate_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_certificate_set_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_certificate_set_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_certificate_set_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -495,12 +534,6 @@ class CertificateSet private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/Certificates/GenesisKeyDelegationCert.h b/lib/include/Cometa/Certificates/GenesisKeyDelegationCert.h index ef6fd895..5913e386 100644 --- a/lib/include/Cometa/Certificates/GenesisKeyDelegationCert.h +++ b/lib/include/Cometa/Certificates/GenesisKeyDelegationCert.h @@ -202,6 +202,37 @@ class GenesisKeyDelegationCert */ bool operator!=(const GenesisKeyDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static GenesisKeyDelegationCert adopt(cardano_genesis_key_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_genesis_key_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_genesis_key_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_genesis_key_delegation_cert_t* release() noexcept; + private: /** @@ -227,11 +258,6 @@ class GenesisKeyDelegationCert */ static void validateHash(const Blake2bHash& value, std::size_t size); - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/MirCert.h b/lib/include/Cometa/Certificates/MirCert.h index bdc9a007..e3b3f53e 100644 --- a/lib/include/Cometa/Certificates/MirCert.h +++ b/lib/include/Cometa/Certificates/MirCert.h @@ -177,6 +177,37 @@ class MirCert */ bool operator!=(const MirCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MirCert adopt(cardano_mir_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_mir_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_mir_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_mir_cert_t* release() noexcept; + private: /** @@ -191,9 +222,6 @@ class MirCert */ cardano_mir_cert_t* checked() const; - /** @brief Allows the outer certificate variant to copy this value. */ - friend class Certificate; - private: /** @brief The owned certificate. */ diff --git a/lib/include/Cometa/Certificates/MirToPotCert.h b/lib/include/Cometa/Certificates/MirToPotCert.h index e5d8899a..a251b56f 100644 --- a/lib/include/Cometa/Certificates/MirToPotCert.h +++ b/lib/include/Cometa/Certificates/MirToPotCert.h @@ -185,6 +185,37 @@ class MirToPotCert */ bool operator!=(const MirToPotCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MirToPotCert adopt(cardano_mir_to_pot_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_mir_to_pot_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_mir_to_pot_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_mir_to_pot_cert_t* release() noexcept; + private: /** @@ -208,11 +239,6 @@ class MirToPotCert */ static void validatePot(MirPotType value); - /** - * @brief Allows MirCert to copy this variant. - */ - friend class MirCert; - private: /** diff --git a/lib/include/Cometa/Certificates/MirToStakeCredentialsCert.h b/lib/include/Cometa/Certificates/MirToStakeCredentialsCert.h index 51d1150e..61cb2bd1 100644 --- a/lib/include/Cometa/Certificates/MirToStakeCredentialsCert.h +++ b/lib/include/Cometa/Certificates/MirToStakeCredentialsCert.h @@ -155,6 +155,37 @@ class MirToStakeCredentialsCert */ bool operator!=(const MirToStakeCredentialsCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MirToStakeCredentialsCert adopt(cardano_mir_to_stake_creds_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_mir_to_stake_creds_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_mir_to_stake_creds_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_mir_to_stake_creds_cert_t* release() noexcept; + private: /** @brief Adopts an owned distribution. @@ -172,9 +203,6 @@ class MirToStakeCredentialsCert */ static void validatePot(MirPotType value); - /** @brief Allows the MIR variant to copy this distribution. */ - friend class MirCert; - private: /** @brief The owned certificate. */ diff --git a/lib/include/Cometa/Certificates/PoolRegistrationCert.h b/lib/include/Cometa/Certificates/PoolRegistrationCert.h index 42a21a56..8784cc4b 100644 --- a/lib/include/Cometa/Certificates/PoolRegistrationCert.h +++ b/lib/include/Cometa/Certificates/PoolRegistrationCert.h @@ -171,6 +171,37 @@ class PoolRegistrationCert */ bool operator!=(const PoolRegistrationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolRegistrationCert adopt(cardano_pool_registration_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pool_registration_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_registration_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pool_registration_cert_t* release() noexcept; + private: /** @@ -187,11 +218,6 @@ class PoolRegistrationCert */ cardano_pool_registration_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/PoolRetirementCert.h b/lib/include/Cometa/Certificates/PoolRetirementCert.h index 74b1bf4d..ec07cf58 100644 --- a/lib/include/Cometa/Certificates/PoolRetirementCert.h +++ b/lib/include/Cometa/Certificates/PoolRetirementCert.h @@ -186,6 +186,37 @@ class PoolRetirementCert */ bool operator!=(const PoolRetirementCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolRetirementCert adopt(cardano_pool_retirement_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pool_retirement_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_retirement_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pool_retirement_cert_t* release() noexcept; + private: /** @@ -202,11 +233,6 @@ class PoolRetirementCert */ cardano_pool_retirement_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/RegisterDRepCert.h b/lib/include/Cometa/Certificates/RegisterDRepCert.h index fd0d3e12..bbc150fb 100644 --- a/lib/include/Cometa/Certificates/RegisterDRepCert.h +++ b/lib/include/Cometa/Certificates/RegisterDRepCert.h @@ -203,6 +203,37 @@ class RegisterDRepCert */ bool operator!=(const RegisterDRepCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static RegisterDRepCert adopt(cardano_register_drep_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_register_drep_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_register_drep_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_register_drep_cert_t* release() noexcept; + private: /** @@ -219,11 +250,6 @@ class RegisterDRepCert */ cardano_register_drep_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/RegistrationCert.h b/lib/include/Cometa/Certificates/RegistrationCert.h index 9901f623..98ff61ad 100644 --- a/lib/include/Cometa/Certificates/RegistrationCert.h +++ b/lib/include/Cometa/Certificates/RegistrationCert.h @@ -186,6 +186,37 @@ class RegistrationCert */ bool operator!=(const RegistrationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static RegistrationCert adopt(cardano_registration_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_registration_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_registration_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_registration_cert_t* release() noexcept; + private: /** @@ -202,11 +233,6 @@ class RegistrationCert */ cardano_registration_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/ResignCommitteeColdCert.h b/lib/include/Cometa/Certificates/ResignCommitteeColdCert.h index fb88c064..2f660526 100644 --- a/lib/include/Cometa/Certificates/ResignCommitteeColdCert.h +++ b/lib/include/Cometa/Certificates/ResignCommitteeColdCert.h @@ -188,6 +188,37 @@ class ResignCommitteeColdCert */ bool operator!=(const ResignCommitteeColdCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ResignCommitteeColdCert adopt(cardano_resign_committee_cold_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_resign_committee_cold_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_resign_committee_cold_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_resign_committee_cold_cert_t* release() noexcept; + private: /** @@ -204,11 +235,6 @@ class ResignCommitteeColdCert */ cardano_resign_committee_cold_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeDelegationCert.h b/lib/include/Cometa/Certificates/StakeDelegationCert.h index 62f8aeeb..67545a84 100644 --- a/lib/include/Cometa/Certificates/StakeDelegationCert.h +++ b/lib/include/Cometa/Certificates/StakeDelegationCert.h @@ -187,6 +187,37 @@ class StakeDelegationCert */ bool operator!=(const StakeDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeDelegationCert adopt(cardano_stake_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_delegation_cert_t* release() noexcept; + private: /** @@ -203,11 +234,6 @@ class StakeDelegationCert */ cardano_stake_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeDeregistrationCert.h b/lib/include/Cometa/Certificates/StakeDeregistrationCert.h index eda1baeb..65301ad1 100644 --- a/lib/include/Cometa/Certificates/StakeDeregistrationCert.h +++ b/lib/include/Cometa/Certificates/StakeDeregistrationCert.h @@ -171,6 +171,37 @@ class StakeDeregistrationCert */ bool operator!=(const StakeDeregistrationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeDeregistrationCert adopt(cardano_stake_deregistration_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_deregistration_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_deregistration_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_deregistration_cert_t* release() noexcept; + private: /** @@ -187,11 +218,6 @@ class StakeDeregistrationCert */ cardano_stake_deregistration_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeRegistrationCert.h b/lib/include/Cometa/Certificates/StakeRegistrationCert.h index 135bc15f..38d07f3d 100644 --- a/lib/include/Cometa/Certificates/StakeRegistrationCert.h +++ b/lib/include/Cometa/Certificates/StakeRegistrationCert.h @@ -171,6 +171,37 @@ class StakeRegistrationCert */ bool operator!=(const StakeRegistrationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeRegistrationCert adopt(cardano_stake_registration_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_registration_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_registration_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_registration_cert_t* release() noexcept; + private: /** @@ -187,11 +218,6 @@ class StakeRegistrationCert */ cardano_stake_registration_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeRegistrationDelegationCert.h b/lib/include/Cometa/Certificates/StakeRegistrationDelegationCert.h index 47523e5f..ede0790d 100644 --- a/lib/include/Cometa/Certificates/StakeRegistrationDelegationCert.h +++ b/lib/include/Cometa/Certificates/StakeRegistrationDelegationCert.h @@ -202,6 +202,37 @@ class StakeRegistrationDelegationCert */ bool operator!=(const StakeRegistrationDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeRegistrationDelegationCert adopt(cardano_stake_registration_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_registration_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_registration_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_registration_delegation_cert_t* release() noexcept; + private: /** @@ -218,11 +249,6 @@ class StakeRegistrationDelegationCert */ cardano_stake_registration_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeVoteDelegationCert.h b/lib/include/Cometa/Certificates/StakeVoteDelegationCert.h index 5d7576c5..59396d70 100644 --- a/lib/include/Cometa/Certificates/StakeVoteDelegationCert.h +++ b/lib/include/Cometa/Certificates/StakeVoteDelegationCert.h @@ -203,6 +203,37 @@ class StakeVoteDelegationCert */ bool operator!=(const StakeVoteDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeVoteDelegationCert adopt(cardano_stake_vote_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_vote_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_vote_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_vote_delegation_cert_t* release() noexcept; + private: /** @@ -219,11 +250,6 @@ class StakeVoteDelegationCert */ cardano_stake_vote_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/StakeVoteRegistrationDelegationCert.h b/lib/include/Cometa/Certificates/StakeVoteRegistrationDelegationCert.h index 0f15332a..b989e04f 100644 --- a/lib/include/Cometa/Certificates/StakeVoteRegistrationDelegationCert.h +++ b/lib/include/Cometa/Certificates/StakeVoteRegistrationDelegationCert.h @@ -217,6 +217,37 @@ class StakeVoteRegistrationDelegationCert */ bool operator!=(const StakeVoteRegistrationDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static StakeVoteRegistrationDelegationCert adopt(cardano_stake_vote_registration_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_stake_vote_registration_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_stake_vote_registration_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_stake_vote_registration_delegation_cert_t* release() noexcept; + private: /** @@ -233,11 +264,6 @@ class StakeVoteRegistrationDelegationCert */ cardano_stake_vote_registration_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/UnregisterDRepCert.h b/lib/include/Cometa/Certificates/UnregisterDRepCert.h index b01f2aae..2792ea8f 100644 --- a/lib/include/Cometa/Certificates/UnregisterDRepCert.h +++ b/lib/include/Cometa/Certificates/UnregisterDRepCert.h @@ -186,6 +186,37 @@ class UnregisterDRepCert */ bool operator!=(const UnregisterDRepCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static UnregisterDRepCert adopt(cardano_unregister_drep_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_unregister_drep_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_unregister_drep_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_unregister_drep_cert_t* release() noexcept; + private: /** @@ -202,11 +233,6 @@ class UnregisterDRepCert */ cardano_unregister_drep_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/UnregistrationCert.h b/lib/include/Cometa/Certificates/UnregistrationCert.h index 99ff2272..bd7c1999 100644 --- a/lib/include/Cometa/Certificates/UnregistrationCert.h +++ b/lib/include/Cometa/Certificates/UnregistrationCert.h @@ -186,6 +186,37 @@ class UnregistrationCert */ bool operator!=(const UnregistrationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static UnregistrationCert adopt(cardano_unregistration_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_unregistration_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_unregistration_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_unregistration_cert_t* release() noexcept; + private: /** @@ -202,11 +233,6 @@ class UnregistrationCert */ cardano_unregistration_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/UpdateDRepCert.h b/lib/include/Cometa/Certificates/UpdateDRepCert.h index 01892b35..fa7dd03e 100644 --- a/lib/include/Cometa/Certificates/UpdateDRepCert.h +++ b/lib/include/Cometa/Certificates/UpdateDRepCert.h @@ -188,6 +188,37 @@ class UpdateDRepCert */ bool operator!=(const UpdateDRepCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static UpdateDRepCert adopt(cardano_update_drep_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_update_drep_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_update_drep_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_update_drep_cert_t* release() noexcept; + private: /** @@ -204,11 +235,6 @@ class UpdateDRepCert */ cardano_update_drep_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/VoteDelegationCert.h b/lib/include/Cometa/Certificates/VoteDelegationCert.h index a92fdc53..1f67040d 100644 --- a/lib/include/Cometa/Certificates/VoteDelegationCert.h +++ b/lib/include/Cometa/Certificates/VoteDelegationCert.h @@ -187,6 +187,37 @@ class VoteDelegationCert */ bool operator!=(const VoteDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VoteDelegationCert adopt(cardano_vote_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_vote_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_vote_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_vote_delegation_cert_t* release() noexcept; + private: /** @@ -203,11 +234,6 @@ class VoteDelegationCert */ cardano_vote_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Certificates/VoteRegistrationDelegationCert.h b/lib/include/Cometa/Certificates/VoteRegistrationDelegationCert.h index 57a2ad30..b65f20b2 100644 --- a/lib/include/Cometa/Certificates/VoteRegistrationDelegationCert.h +++ b/lib/include/Cometa/Certificates/VoteRegistrationDelegationCert.h @@ -202,6 +202,37 @@ class VoteRegistrationDelegationCert */ bool operator!=(const VoteRegistrationDelegationCert& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VoteRegistrationDelegationCert adopt(cardano_vote_registration_delegation_cert_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_vote_registration_delegation_cert_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_vote_registration_delegation_cert_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_vote_registration_delegation_cert_t* release() noexcept; + private: /** @@ -218,11 +249,6 @@ class VoteRegistrationDelegationCert */ cardano_vote_registration_delegation_cert_t* checked() const; - /** - * @brief Allows Certificate to copy this variant. - */ - friend class Certificate; - private: /** diff --git a/lib/include/Cometa/Common/Anchor.h b/lib/include/Cometa/Common/Anchor.h index 72cfa061..1677e147 100644 --- a/lib/include/Cometa/Common/Anchor.h +++ b/lib/include/Cometa/Common/Anchor.h @@ -200,13 +200,38 @@ class Anchor */ bool operator!=(const Anchor& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Anchor adopt(cardano_anchor_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_anchor_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_anchor_t* nativeHandle() const noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_anchor_t* release() noexcept; - /** @brief Allows voting procedures to copy metadata anchors. */ - friend class VotingProcedure; + private: /** * @brief Takes ownership of an existing value. @@ -226,18 +251,6 @@ class Anchor */ cardano_anchor_t* checked() const; - /** @brief Allows DRep registration certificates to copy anchors. */ - friend class RegisterDRepCert; - - /** @brief Allows DRep update certificates to copy anchors. */ - friend class UpdateDRepCert; - - /** @brief Allows committee resignation certificates to copy anchors. */ - friend class ResignCommitteeColdCert; - - /** @brief Allows constitutions to copy anchors. */ - friend class Constitution; - private: /** diff --git a/lib/include/Cometa/Common/BigInt.h b/lib/include/Cometa/Common/BigInt.h index 8dbc3c6e..fd696fb2 100644 --- a/lib/include/Cometa/Common/BigInt.h +++ b/lib/include/Cometa/Common/BigInt.h @@ -51,23 +51,6 @@ namespace Cometa */ class BigInt { - private: - - /** @brief Allows Plutus data to copy integer components. */ - friend class PlutusData; - - /** @brief Allows Metadatum to copy integer values. */ - friend class Metadatum; - - /** @brief Allows CBOR decoding to adopt a decoded integer. */ - friend class CborReader; - - /** @brief Allows CBOR encoding to read the integer. */ - friend class CborWriter; - - /** @brief Allows JSON encoding to read the integer. */ - friend class JsonWriter; - public: /** @@ -603,6 +586,37 @@ class BigInt */ bool operator>=(const BigInt& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static BigInt adopt(cardano_bigint_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_bigint_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bigint_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_bigint_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Common/Credential.h b/lib/include/Cometa/Common/Credential.h index f0614dd9..81a3424c 100644 --- a/lib/include/Cometa/Common/Credential.h +++ b/lib/include/Cometa/Common/Credential.h @@ -219,91 +219,38 @@ class Credential */ bool operator<(const Credential& other) const; - private: - - /** @brief Allows guard sets to copy credentials. */ - friend class GuardSet; - - /** @brief Allows required guard maps to copy credentials. */ - friend class RequiredGuardsMap; - - /** @brief Allows RegistrationCert to copy its credential. */ - friend class RegistrationCert; - - /** @brief Allows UnregistrationCert to copy its credential. */ - friend class UnregistrationCert; - - /** @brief Allows StakeRegistrationDelegationCert to copy its credential. */ - friend class StakeRegistrationDelegationCert; - - /** @brief Allows StakeDelegationCert to copy its credential. */ - friend class StakeDelegationCert; - - /** @brief Allows StakeDeregistrationCert to copy its credential. */ - friend class StakeDeregistrationCert; - - /** @brief Allows StakeRegistrationCert to copy its credential. */ - friend class StakeRegistrationCert; - - /** @brief Allows MIR distributions to copy their credentials. */ - friend class MirToStakeCredentialsCert; - - /** @brief Allows DRep values to copy their credentials. */ - friend class DRep; - - /** @brief Allows vote delegation certificates to copy credentials. */ - friend class VoteDelegationCert; - - /** @brief Allows combined delegation certificates to copy credentials. */ - friend class StakeVoteDelegationCert; - - /** @brief Allows vote registration certificates to copy credentials. */ - friend class VoteRegistrationDelegationCert; - - /** @brief Allows combined registration certificates to copy credentials. */ - friend class StakeVoteRegistrationDelegationCert; - - /** @brief Allows DRep unregistration certificates to copy credentials. */ - friend class UnregisterDRepCert; - - /** @brief Allows DRep registration certificates to copy credentials. */ - friend class RegisterDRepCert; - - /** @brief Allows DRep update certificates to copy credentials. */ - friend class UpdateDRepCert; - - /** @brief Allows committee authorization certificates to copy credentials. */ - friend class AuthCommitteeHotCert; - - /** @brief Allows committee resignation certificates to copy credentials. */ - friend class ResignCommitteeColdCert; - - /** @brief Allows ScriptRequireGuard to copy script components. */ - friend class ScriptRequireGuard; - - /** @brief Allows CredentialSet to copy set elements. */ - friend class CredentialSet; - - /** @brief Allows CommitteeMembersMap to copy member credentials. */ - friend class CommitteeMembersMap; - - /** @brief Allows committees to copy member credentials. */ - friend class Committee; + public: - /** @brief Allows voters to copy their credentials. */ - friend class Voter; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Credential adopt(cardano_credential_t* value); - /** @brief Allows BaseAddress to copy credential components. */ - friend class BaseAddress; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_credential_t* nativeHandle() noexcept; - /** @brief Allows EnterpriseAddress to copy credential components. */ - friend class EnterpriseAddress; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_credential_t* nativeHandle() const noexcept; - /** @brief Allows RewardAddress to copy credential components. */ - friend class RewardAddress; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_credential_t* release() noexcept; - /** @brief Allows PointerAddress to copy credential components. */ - friend class PointerAddress; + private: /** * @brief Takes ownership of an existing value. diff --git a/lib/include/Cometa/Common/CredentialSet.h b/lib/include/Cometa/Common/CredentialSet.h index f23ab135..0acb9b10 100644 --- a/lib/include/Cometa/Common/CredentialSet.h +++ b/lib/include/Cometa/Common/CredentialSet.h @@ -397,6 +397,39 @@ class CredentialSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CredentialSet adopt(cardano_credential_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_credential_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_credential_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_credential_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -429,15 +462,6 @@ class CredentialSet */ explicit CredentialSet(cardano_credential_set_t* value) noexcept; - /** @brief Allows CommitteeMembersMap to return member credentials. */ - friend class CommitteeMembersMap; - - /** @brief Allows committees to return member credentials. */ - friend class Committee; - - /** @brief Allows update actions to copy member credentials. */ - friend class UpdateCommitteeAction; - private: /** diff --git a/lib/include/Cometa/Common/DRep.h b/lib/include/Cometa/Common/DRep.h index 1b631687..fcae12f7 100644 --- a/lib/include/Cometa/Common/DRep.h +++ b/lib/include/Cometa/Common/DRep.h @@ -184,6 +184,37 @@ class DRep */ bool operator!=(const DRep& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static DRep adopt(cardano_drep_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_drep_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_drep_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_drep_t* release() noexcept; + private: /** @@ -205,18 +236,6 @@ class DRep */ static void validate(DRepType type, const std::optional& value); - /** @brief Allows certificate values to copy DRep references. */ - friend class VoteDelegationCert; - - /** @brief Allows combined delegation certificates to copy DRep references. */ - friend class StakeVoteDelegationCert; - - /** @brief Allows vote registration certificates to copy DRep references. */ - friend class VoteRegistrationDelegationCert; - - /** @brief Allows combined registration certificates to copy DRep references. */ - friend class StakeVoteRegistrationDelegationCert; - private: /** @brief The owned DRep. */ diff --git a/lib/include/Cometa/Common/Datum.h b/lib/include/Cometa/Common/Datum.h index d3c2185c..cedbfa61 100644 --- a/lib/include/Cometa/Common/Datum.h +++ b/lib/include/Cometa/Common/Datum.h @@ -201,10 +201,38 @@ class Datum */ bool operator!=(const Datum& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Datum adopt(cardano_datum_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_datum_t* nativeHandle() noexcept; - /** @brief Allows TransactionOutput to copy components. */ - friend class TransactionOutput; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_datum_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_datum_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Common/ExUnits.h b/lib/include/Cometa/Common/ExUnits.h index 2b1f9b8c..3fef75f9 100644 --- a/lib/include/Cometa/Common/ExUnits.h +++ b/lib/include/Cometa/Common/ExUnits.h @@ -192,14 +192,36 @@ class ExUnits */ bool operator!=(const ExUnits& other) const; - /** @brief Allows redeemers to copy their execution units. */ - friend class Redeemer; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ExUnits adopt(cardano_ex_units_t* value); - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ex_units_t* nativeHandle() noexcept; - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ex_units_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_ex_units_t* release() noexcept; private: diff --git a/lib/include/Cometa/Common/GovernanceActionId.h b/lib/include/Cometa/Common/GovernanceActionId.h index b6e9fc26..a0c6dda1 100644 --- a/lib/include/Cometa/Common/GovernanceActionId.h +++ b/lib/include/Cometa/Common/GovernanceActionId.h @@ -218,25 +218,38 @@ class GovernanceActionId */ bool operator!=(const GovernanceActionId& other) const; - private: - - /** @brief Allows voting maps to transfer independent values. */ - friend class VotingProcedures; + public: - /** @brief Allows governance actions to copy identifiers. */ - friend class NoConfidenceAction; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static GovernanceActionId adopt(cardano_governance_action_id_t* value); - /** @brief Allows hard fork actions to copy identifiers. */ - friend class HardForkInitiationAction; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_governance_action_id_t* nativeHandle() noexcept; - /** @brief Allows parameter change actions to copy identifiers. */ - friend class ParameterChangeAction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_governance_action_id_t* nativeHandle() const noexcept; - /** @brief Allows constitution actions to copy identifiers. */ - friend class NewConstitutionAction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_governance_action_id_t* release() noexcept; - /** @brief Allows committee updates to copy previous action IDs. */ - friend class UpdateCommitteeAction; + private: /** * @brief Takes ownership of an existing value. diff --git a/lib/include/Cometa/Common/ProtocolVersion.h b/lib/include/Cometa/Common/ProtocolVersion.h index c90ce346..516f03a3 100644 --- a/lib/include/Cometa/Common/ProtocolVersion.h +++ b/lib/include/Cometa/Common/ProtocolVersion.h @@ -196,14 +196,36 @@ class ProtocolVersion */ bool operator!=(const ProtocolVersion& other) const; - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProtocolVersion adopt(cardano_protocol_version_t* value); - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_protocol_version_t* nativeHandle() noexcept; - /** @brief Allows hard fork actions to copy protocol versions. */ - friend class HardForkInitiationAction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_protocol_version_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_protocol_version_t* release() noexcept; private: diff --git a/lib/include/Cometa/Common/UnitInterval.h b/lib/include/Cometa/Common/UnitInterval.h index 029325cc..14633726 100644 --- a/lib/include/Cometa/Common/UnitInterval.h +++ b/lib/include/Cometa/Common/UnitInterval.h @@ -216,29 +216,36 @@ class UnitInterval */ bool operator!=(const UnitInterval& other) const; - /** @brief Allows PoolParams to copy pool components. */ - friend class PoolParams; - - /** @brief Allows ExUnitPrices to copy price components. */ - friend class ExUnitPrices; - - /** @brief Allows voting thresholds to copy their components. */ - friend class DRepVotingThresholds; - - /** @brief Allows voting thresholds to copy their components. */ - friend class PoolVotingThresholds; + public: - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static UnitInterval adopt(cardano_unit_interval_t* value); - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_unit_interval_t* nativeHandle() noexcept; - /** @brief Allows committees to copy quorum thresholds. */ - friend class Committee; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_unit_interval_t* nativeHandle() const noexcept; - /** @brief Allows update actions to copy quorum thresholds. */ - friend class UpdateCommitteeAction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_unit_interval_t* release() noexcept; private: diff --git a/lib/include/Cometa/Common/Utxo.h b/lib/include/Cometa/Common/Utxo.h index 6fa19f9c..e68fcfe6 100644 --- a/lib/include/Cometa/Common/Utxo.h +++ b/lib/include/Cometa/Common/Utxo.h @@ -189,10 +189,38 @@ class Utxo */ bool operator!=(const Utxo& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Utxo adopt(cardano_utxo_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_utxo_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_utxo_t* nativeHandle() const noexcept; - /** @brief Allows transactions to use this value. */ - friend class Transaction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_utxo_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. @@ -212,11 +240,6 @@ class Utxo */ cardano_utxo_t* checked() const; - /** - * @brief Checks the decoded value invariants. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/Common/WithdrawalMap.h b/lib/include/Cometa/Common/WithdrawalMap.h index dc2aca22..1ac4288e 100644 --- a/lib/include/Cometa/Common/WithdrawalMap.h +++ b/lib/include/Cometa/Common/WithdrawalMap.h @@ -513,6 +513,45 @@ class WithdrawalMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static WithdrawalMap adopt(cardano_withdrawal_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_withdrawal_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_withdrawal_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_withdrawal_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -540,15 +579,6 @@ class WithdrawalMap private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - - /** @brief Allows treasury actions to copy withdrawals. */ - friend class TreasuryWithdrawalsAction; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/Crypto/Bip32PrivateKey.h b/lib/include/Cometa/Crypto/Bip32PrivateKey.h index 587ff1f8..dad9959f 100644 --- a/lib/include/Cometa/Crypto/Bip32PrivateKey.h +++ b/lib/include/Cometa/Crypto/Bip32PrivateKey.h @@ -151,6 +151,37 @@ class Bip32PrivateKey */ Bip32PrivateKey& operator=(Bip32PrivateKey&& other) noexcept; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Bip32PrivateKey adopt(cardano_bip32_private_key_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_bip32_private_key_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bip32_private_key_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_bip32_private_key_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/Crypto/Bip32PublicKey.h b/lib/include/Cometa/Crypto/Bip32PublicKey.h index 96286860..4877de0f 100644 --- a/lib/include/Cometa/Crypto/Bip32PublicKey.h +++ b/lib/include/Cometa/Crypto/Bip32PublicKey.h @@ -156,12 +156,38 @@ class Bip32PublicKey */ bool operator!=(const Bip32PublicKey& other) const; - private: + public: /** - * @brief Allows Bip32PrivateKey to transfer or inspect key material. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - friend class Bip32PrivateKey; + static Bip32PublicKey adopt(cardano_bip32_public_key_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_bip32_public_key_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bip32_public_key_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_bip32_public_key_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/Crypto/Blake2bHash.h b/lib/include/Cometa/Crypto/Blake2bHash.h index 0bc8499d..c49c5a92 100644 --- a/lib/include/Cometa/Crypto/Blake2bHash.h +++ b/lib/include/Cometa/Crypto/Blake2bHash.h @@ -235,73 +235,38 @@ class Blake2bHash */ bool operator<(const Blake2bHash& other) const; - private: - - /** @brief Allows transactions to use this value. */ - friend class Transaction; - - /** @brief Allows sub-transaction sets to copy this value. */ - friend class SubTransactionSet; - - /** @brief Allows sub-transactions to copy this value. */ - friend class SubTransaction; - - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - - /** @brief Allows parameter change actions to copy policy hashes. */ - friend class ParameterChangeAction; - - /** @brief Allows constitutions to copy script hashes. */ - friend class Constitution; - - /** @brief Allows treasury actions to copy policy hashes. */ - friend class TreasuryWithdrawalsAction; - - /** @brief Allows GenesisKeyDelegationCert to copy its hashes. */ - friend class GenesisKeyDelegationCert; - - /** @brief Allows PoolRetirementCert to copy its pool key hash. */ - friend class PoolRetirementCert; - - /** @brief Allows StakeRegistrationDelegationCert to copy its pool key hash. */ - friend class StakeRegistrationDelegationCert; - - /** @brief Allows StakeDelegationCert to copy its pool key hash. */ - friend class StakeDelegationCert; - - /** @brief Allows combined delegation certificates to copy pool hashes. */ - friend class StakeVoteDelegationCert; - - /** @brief Allows combined registration certificates to copy pool hashes. */ - friend class StakeVoteRegistrationDelegationCert; - - /** @brief Allows PoolParams to copy pool components. */ - friend class PoolParams; - - /** @brief Allows TransactionInput to copy components. */ - friend class TransactionInput; - - /** @brief Allows ScriptPubkey to copy script components. */ - friend class ScriptPubkey; + public: - /** @brief Allows Blake2bHashSet to copy set elements. */ - friend class Blake2bHashSet; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Blake2bHash adopt(cardano_blake2b_hash_t* value); - /** @brief Allows proposed parameter updates to copy hash keys. */ - friend class ProposedParamUpdates; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_blake2b_hash_t* nativeHandle() noexcept; - /** @brief Allows MultiAsset to copy policy components. */ - friend class MultiAsset; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_blake2b_hash_t* nativeHandle() const noexcept; - /** @brief Allows AssetId to copy identifier components. */ - friend class AssetId; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_blake2b_hash_t* release() noexcept; - /** @brief Allows ByronAddress to copy credential components. */ - friend class ByronAddress; + private: /** * @brief Takes ownership of an existing value. @@ -310,16 +275,6 @@ class Blake2bHash */ explicit Blake2bHash(cardano_blake2b_hash_t* value) noexcept; - /** - * @brief Allows public-key hashing to adopt the returned digest. - */ - friend class Ed25519PublicKey; - - /** - * @brief Allows extended public-key hashing to adopt the returned digest. - */ - friend class Bip32PublicKey; - private: /** @@ -335,11 +290,6 @@ class Blake2bHash /** @brief The owned reference, or null after a move. */ cardano_blake2b_hash_t* m_value; - /** @brief Allows pool metadata to exchange content hashes. */ - friend class PoolMetadata; - - /** @brief Allows pool owners to copy hashes. */ - friend class PoolOwners; }; } // namespace Cometa diff --git a/lib/include/Cometa/Crypto/Blake2bHashSet.h b/lib/include/Cometa/Crypto/Blake2bHashSet.h index bc835f3e..f0feda4e 100644 --- a/lib/include/Cometa/Crypto/Blake2bHashSet.h +++ b/lib/include/Cometa/Crypto/Blake2bHashSet.h @@ -397,6 +397,39 @@ class Blake2bHashSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Blake2bHashSet adopt(cardano_blake2b_hash_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_blake2b_hash_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_blake2b_hash_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_blake2b_hash_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -422,12 +455,6 @@ class Blake2bHashSet private: - /** @brief Allows transactions to use this value. */ - friend class Transaction; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts one owned native set. * diff --git a/lib/include/Cometa/Crypto/Ed25519PrivateKey.h b/lib/include/Cometa/Crypto/Ed25519PrivateKey.h index a74f8132..d42bd2a1 100644 --- a/lib/include/Cometa/Crypto/Ed25519PrivateKey.h +++ b/lib/include/Cometa/Crypto/Ed25519PrivateKey.h @@ -158,12 +158,38 @@ class Ed25519PrivateKey */ Ed25519PrivateKey& operator=(Ed25519PrivateKey&& other) noexcept; - private: + public: /** - * @brief Allows Bip32PrivateKey to transfer or inspect key material. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - friend class Bip32PrivateKey; + static Ed25519PrivateKey adopt(cardano_ed25519_private_key_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ed25519_private_key_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ed25519_private_key_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_ed25519_private_key_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/Crypto/Ed25519PublicKey.h b/lib/include/Cometa/Crypto/Ed25519PublicKey.h index 64d67aac..08bc30f9 100644 --- a/lib/include/Cometa/Crypto/Ed25519PublicKey.h +++ b/lib/include/Cometa/Crypto/Ed25519PublicKey.h @@ -150,23 +150,38 @@ class Ed25519PublicKey */ bool operator!=(const Ed25519PublicKey& other) const; - private: + public: /** - * @brief Allows Ed25519PrivateKey to transfer or inspect key material. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - /** @brief Allows key witnesses to copy signed values. */ - friend class VkeyWitness; + static Ed25519PublicKey adopt(cardano_ed25519_public_key_t* value); - /** @brief Allows bootstrap witnesses to copy signed values. */ - friend class BootstrapWitness; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ed25519_public_key_t* nativeHandle() noexcept; - friend class Ed25519PrivateKey; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ed25519_public_key_t* nativeHandle() const noexcept; /** - * @brief Allows Bip32PublicKey to transfer or inspect key material. + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. */ - friend class Bip32PublicKey; + cardano_ed25519_public_key_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/Crypto/Ed25519Signature.h b/lib/include/Cometa/Crypto/Ed25519Signature.h index 009af1d3..d40459ef 100644 --- a/lib/include/Cometa/Crypto/Ed25519Signature.h +++ b/lib/include/Cometa/Crypto/Ed25519Signature.h @@ -133,23 +133,38 @@ class Ed25519Signature */ bool operator!=(const Ed25519Signature& other) const; - private: + public: /** - * @brief Allows Ed25519PrivateKey to transfer or inspect key material. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - /** @brief Allows key witnesses to copy signed values. */ - friend class VkeyWitness; + static Ed25519Signature adopt(cardano_ed25519_signature_t* value); - /** @brief Allows bootstrap witnesses to copy signed values. */ - friend class BootstrapWitness; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ed25519_signature_t* nativeHandle() noexcept; - friend class Ed25519PrivateKey; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ed25519_signature_t* nativeHandle() const noexcept; /** - * @brief Allows Ed25519PublicKey to transfer or inspect key material. + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. */ - friend class Ed25519PublicKey; + cardano_ed25519_signature_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/Json/JsonValue.h b/lib/include/Cometa/Json/JsonValue.h index b63adf85..c5bbeb87 100644 --- a/lib/include/Cometa/Json/JsonValue.h +++ b/lib/include/Cometa/Json/JsonValue.h @@ -210,12 +210,38 @@ class JsonValue */ JsonValue& operator=(JsonValue&& other) noexcept; - private: + public: /** - * @brief Allows the JSON writer to inspect the parsed value. + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. */ - friend class JsonWriter; + static JsonValue adopt(cardano_json_object_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_json_object_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_json_object_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_json_object_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/Json/JsonWriter.h b/lib/include/Cometa/Json/JsonWriter.h index 84aff34d..cd5c755d 100644 --- a/lib/include/Cometa/Json/JsonWriter.h +++ b/lib/include/Cometa/Json/JsonWriter.h @@ -238,6 +238,47 @@ class JsonWriter */ JsonWriter& operator=(JsonWriter&& other) noexcept; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @param format The format used to create the native writer; preserved by reset(). + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null or the format is invalid; ownership is not transferred. + */ + static JsonWriter adopt(cardano_json_writer_t* value, JsonFormat format); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_json_writer_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_json_writer_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_json_writer_t* release() noexcept; + + private: + + /** + * @brief Takes ownership of a validated native reference. + * @param value The owned non-null reference. + * @param format The format to preserve when resetting. + */ + explicit JsonWriter(cardano_json_writer_t* value, JsonFormat format) noexcept; + private: /** diff --git a/lib/include/Cometa/KeyHandlers/SecureKeyHandler.h b/lib/include/Cometa/KeyHandlers/SecureKeyHandler.h index 53ff8f40..49108610 100644 --- a/lib/include/Cometa/KeyHandlers/SecureKeyHandler.h +++ b/lib/include/Cometa/KeyHandlers/SecureKeyHandler.h @@ -205,6 +205,22 @@ class SecureKeyHandler */ SecureKeyHandler& operator=(SecureKeyHandler&& other) noexcept; + public: + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_secure_key_handler_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_secure_key_handler_t* nativeHandle() const noexcept; + private: /** diff --git a/lib/include/Cometa/PlutusData/ConstrPlutusData.h b/lib/include/Cometa/PlutusData/ConstrPlutusData.h index 6755cb08..acb931e8 100644 --- a/lib/include/Cometa/PlutusData/ConstrPlutusData.h +++ b/lib/include/Cometa/PlutusData/ConstrPlutusData.h @@ -197,10 +197,38 @@ class ConstrPlutusData */ bool operator!=(const ConstrPlutusData& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ConstrPlutusData adopt(cardano_constr_plutus_data_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_constr_plutus_data_t* nativeHandle() noexcept; - /** @brief Allows PlutusData to copy components. */ - friend class PlutusData; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_constr_plutus_data_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_constr_plutus_data_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/PlutusData/PlutusData.h b/lib/include/Cometa/PlutusData/PlutusData.h index a0e0a976..14daf4dd 100644 --- a/lib/include/Cometa/PlutusData/PlutusData.h +++ b/lib/include/Cometa/PlutusData/PlutusData.h @@ -295,28 +295,38 @@ class PlutusData */ bool operator!=(const PlutusData& other) const; - private: - - /** @brief Allows required guard maps to copy data. */ - friend class RequiredGuardsMap; - - /** @brief Allows PlutusList to copy components. */ - friend class PlutusList; + public: - /** @brief Allows witness sets to copy data values. */ - friend class PlutusDataSet; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusData adopt(cardano_plutus_data_t* value); - /** @brief Allows PlutusMap to copy components. */ - friend class PlutusMap; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_plutus_data_t* nativeHandle() noexcept; - /** @brief Allows redeemers to copy their data. */ - friend class Redeemer; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_data_t* nativeHandle() const noexcept; - /** @brief Allows Datum to copy components. */ - friend class Datum; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_plutus_data_t* release() noexcept; - /** @brief Allows protocol updates to return Plutus data. */ - friend class ProtocolParamUpdate; + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/PlutusData/PlutusList.h b/lib/include/Cometa/PlutusData/PlutusList.h index 8e70362c..89d95662 100644 --- a/lib/include/Cometa/PlutusData/PlutusList.h +++ b/lib/include/Cometa/PlutusData/PlutusList.h @@ -519,6 +519,45 @@ class PlutusList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusList adopt(cardano_plutus_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -536,27 +575,6 @@ class PlutusList private: - /** @brief Allows PlutusV1Script to apply data parameters. */ - friend class PlutusV1Script; - - /** @brief Allows PlutusV2Script to apply data parameters. */ - friend class PlutusV2Script; - - /** @brief Allows PlutusV3Script to apply data parameters. */ - friend class PlutusV3Script; - - /** @brief Allows PlutusV4Script to apply data parameters. */ - friend class PlutusV4Script; - - /** @brief Allows PlutusData to copy components. */ - friend class PlutusData; - - /** @brief Allows PlutusMap to copy components. */ - friend class PlutusMap; - - /** @brief Allows ConstrPlutusData to copy components. */ - friend class ConstrPlutusData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/PlutusData/PlutusMap.h b/lib/include/Cometa/PlutusData/PlutusMap.h index 39e47f85..2b60c58c 100644 --- a/lib/include/Cometa/PlutusData/PlutusMap.h +++ b/lib/include/Cometa/PlutusData/PlutusMap.h @@ -552,6 +552,45 @@ class PlutusMap m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusMap adopt(cardano_plutus_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_plutus_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_plutus_map_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -569,9 +608,6 @@ class PlutusMap private: - /** @brief Allows PlutusData to copy components. */ - friend class PlutusData; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/PoolParams/BlsKey.h b/lib/include/Cometa/PoolParams/BlsKey.h index 937a7e2f..df60fcf7 100644 --- a/lib/include/Cometa/PoolParams/BlsKey.h +++ b/lib/include/Cometa/PoolParams/BlsKey.h @@ -180,6 +180,37 @@ class BlsKey */ bool operator!=(const BlsKey& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static BlsKey adopt(cardano_bls_key_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_bls_key_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bls_key_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_bls_key_t* release() noexcept; + private: /** @@ -206,9 +237,6 @@ class BlsKey * @brief The owned reference, or null after a move. */ cardano_bls_key_t* m_value; - - /** @brief Allows PoolParams to exchange component values. */ - friend class PoolParams; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/Ipv4.h b/lib/include/Cometa/PoolParams/Ipv4.h index 45447c81..f60b00f2 100644 --- a/lib/include/Cometa/PoolParams/Ipv4.h +++ b/lib/include/Cometa/PoolParams/Ipv4.h @@ -171,6 +171,37 @@ class Ipv4 */ bool operator!=(const Ipv4& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Ipv4 adopt(cardano_ipv4_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ipv4_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ipv4_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_ipv4_t* release() noexcept; + private: /** @@ -197,9 +228,6 @@ class Ipv4 * @brief The owned reference, or null after a move. */ cardano_ipv4_t* m_value; - - /** @brief Allows SingleHostAddrRelay to exchange component values. */ - friend class SingleHostAddrRelay; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/Ipv6.h b/lib/include/Cometa/PoolParams/Ipv6.h index 08fd82ab..469ae9a5 100644 --- a/lib/include/Cometa/PoolParams/Ipv6.h +++ b/lib/include/Cometa/PoolParams/Ipv6.h @@ -171,6 +171,37 @@ class Ipv6 */ bool operator!=(const Ipv6& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Ipv6 adopt(cardano_ipv6_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ipv6_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ipv6_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_ipv6_t* release() noexcept; + private: /** @@ -197,9 +228,6 @@ class Ipv6 * @brief The owned reference, or null after a move. */ cardano_ipv6_t* m_value; - - /** @brief Allows SingleHostAddrRelay to exchange component values. */ - friend class SingleHostAddrRelay; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/MultiHostNameRelay.h b/lib/include/Cometa/PoolParams/MultiHostNameRelay.h index 1cbd94b5..fcff8748 100644 --- a/lib/include/Cometa/PoolParams/MultiHostNameRelay.h +++ b/lib/include/Cometa/PoolParams/MultiHostNameRelay.h @@ -170,6 +170,37 @@ class MultiHostNameRelay */ bool operator!=(const MultiHostNameRelay& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static MultiHostNameRelay adopt(cardano_multi_host_name_relay_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_multi_host_name_relay_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_multi_host_name_relay_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_multi_host_name_relay_t* release() noexcept; + private: /** @@ -203,9 +234,6 @@ class MultiHostNameRelay * @brief The owned reference, or null after a move. */ cardano_multi_host_name_relay_t* m_value; - - /** @brief Allows Relay to exchange component values. */ - friend class Relay; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/PoolMetadata.h b/lib/include/Cometa/PoolParams/PoolMetadata.h index 413b07f1..a695ba4e 100644 --- a/lib/include/Cometa/PoolParams/PoolMetadata.h +++ b/lib/include/Cometa/PoolParams/PoolMetadata.h @@ -186,6 +186,37 @@ class PoolMetadata */ bool operator!=(const PoolMetadata& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolMetadata adopt(cardano_pool_metadata_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pool_metadata_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_metadata_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pool_metadata_t* release() noexcept; + private: /** @@ -226,9 +257,6 @@ class PoolMetadata * @brief The owned reference, or null after a move. */ cardano_pool_metadata_t* m_value; - - /** @brief Allows PoolParams to exchange component values. */ - friend class PoolParams; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/PoolOwners.h b/lib/include/Cometa/PoolParams/PoolOwners.h index 4a1315d8..b7833864 100644 --- a/lib/include/Cometa/PoolParams/PoolOwners.h +++ b/lib/include/Cometa/PoolParams/PoolOwners.h @@ -400,6 +400,39 @@ class PoolOwners } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolOwners adopt(cardano_pool_owners_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_pool_owners_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_owners_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_pool_owners_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -454,9 +487,6 @@ class PoolOwners */ static void validateHash(const Blake2bHash& value); - /** @brief Allows pool parameters to copy the collection. */ - friend class PoolParams; - private: /** diff --git a/lib/include/Cometa/PoolParams/PoolParams.h b/lib/include/Cometa/PoolParams/PoolParams.h index 8ac912e1..6835c9f9 100644 --- a/lib/include/Cometa/PoolParams/PoolParams.h +++ b/lib/include/Cometa/PoolParams/PoolParams.h @@ -313,10 +313,38 @@ class PoolParams */ bool operator!=(const PoolParams& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolParams adopt(cardano_pool_params_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pool_params_t* nativeHandle() noexcept; - /** @brief Allows pool registration certificates to copy their parameters. */ - friend class PoolRegistrationCert; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_params_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pool_params_t* release() noexcept; + + private: /** * @brief Adopts an owned native value. diff --git a/lib/include/Cometa/PoolParams/Relay.h b/lib/include/Cometa/PoolParams/Relay.h index 9c76e8d3..bc5e8797 100644 --- a/lib/include/Cometa/PoolParams/Relay.h +++ b/lib/include/Cometa/PoolParams/Relay.h @@ -227,6 +227,37 @@ class Relay */ bool operator!=(const Relay& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Relay adopt(cardano_relay_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_relay_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_relay_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_relay_t* release() noexcept; + private: /** @@ -253,9 +284,6 @@ class Relay * @brief The owned reference, or null after a move. */ cardano_relay_t* m_value; - - /** @brief Allows Relays to exchange component values. */ - friend class Relays; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/Relays.h b/lib/include/Cometa/PoolParams/Relays.h index b1fc666e..b9f3b616 100644 --- a/lib/include/Cometa/PoolParams/Relays.h +++ b/lib/include/Cometa/PoolParams/Relays.h @@ -509,6 +509,45 @@ class Relays m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Relays adopt(cardano_relays_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_relays_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_relays_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_relays_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,9 +565,6 @@ class Relays private: - /** @brief Allows PoolParams to copy relay collections. */ - friend class PoolParams; - /** * @brief Takes ownership of an existing reference. * diff --git a/lib/include/Cometa/PoolParams/SingleHostAddrRelay.h b/lib/include/Cometa/PoolParams/SingleHostAddrRelay.h index af95c19b..38740df3 100644 --- a/lib/include/Cometa/PoolParams/SingleHostAddrRelay.h +++ b/lib/include/Cometa/PoolParams/SingleHostAddrRelay.h @@ -203,6 +203,37 @@ class SingleHostAddrRelay */ bool operator!=(const SingleHostAddrRelay& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static SingleHostAddrRelay adopt(cardano_single_host_addr_relay_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_single_host_addr_relay_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_single_host_addr_relay_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_single_host_addr_relay_t* release() noexcept; + private: /** @@ -229,9 +260,6 @@ class SingleHostAddrRelay * @brief The owned reference, or null after a move. */ cardano_single_host_addr_relay_t* m_value; - - /** @brief Allows Relay to exchange component values. */ - friend class Relay; }; } // namespace Cometa diff --git a/lib/include/Cometa/PoolParams/SingleHostNameRelay.h b/lib/include/Cometa/PoolParams/SingleHostNameRelay.h index c5001618..7ff493c8 100644 --- a/lib/include/Cometa/PoolParams/SingleHostNameRelay.h +++ b/lib/include/Cometa/PoolParams/SingleHostNameRelay.h @@ -185,6 +185,37 @@ class SingleHostNameRelay */ bool operator!=(const SingleHostNameRelay& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static SingleHostNameRelay adopt(cardano_single_host_name_relay_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_single_host_name_relay_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_single_host_name_relay_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_single_host_name_relay_t* release() noexcept; + private: /** @@ -218,9 +249,6 @@ class SingleHostNameRelay * @brief The owned reference, or null after a move. */ cardano_single_host_name_relay_t* m_value; - - /** @brief Allows Relay to exchange component values. */ - friend class Relay; }; } // namespace Cometa diff --git a/lib/include/Cometa/ProposalProcedures/Committee.h b/lib/include/Cometa/ProposalProcedures/Committee.h index 998631c1..c8c47571 100644 --- a/lib/include/Cometa/ProposalProcedures/Committee.h +++ b/lib/include/Cometa/ProposalProcedures/Committee.h @@ -187,6 +187,37 @@ class Committee */ bool operator!=(const Committee& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Committee adopt(cardano_committee_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_committee_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_committee_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_committee_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/ProposalProcedures/CommitteeMembersMap.h b/lib/include/Cometa/ProposalProcedures/CommitteeMembersMap.h index 0a752574..5ebfb8cf 100644 --- a/lib/include/Cometa/ProposalProcedures/CommitteeMembersMap.h +++ b/lib/include/Cometa/ProposalProcedures/CommitteeMembersMap.h @@ -480,6 +480,45 @@ class CommitteeMembersMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CommitteeMembersMap adopt(cardano_committee_members_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_committee_members_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_committee_members_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_committee_members_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -507,9 +546,6 @@ class CommitteeMembersMap private: - /** @brief Allows update actions to copy member terms. */ - friend class UpdateCommitteeAction; - /** * @brief Adopts an owned member map. * @param value The owned map. diff --git a/lib/include/Cometa/ProposalProcedures/Constitution.h b/lib/include/Cometa/ProposalProcedures/Constitution.h index 7fba7818..eec0ffdb 100644 --- a/lib/include/Cometa/ProposalProcedures/Constitution.h +++ b/lib/include/Cometa/ProposalProcedures/Constitution.h @@ -164,10 +164,38 @@ class Constitution */ bool operator!=(const Constitution& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Constitution adopt(cardano_constitution_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_constitution_t* nativeHandle() noexcept; - /** @brief Allows governance actions to copy constitutions. */ - friend class NewConstitutionAction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_constitution_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_constitution_t* release() noexcept; + + private: /** * @brief Adopts an owned constitution. diff --git a/lib/include/Cometa/ProposalProcedures/HardForkInitiationAction.h b/lib/include/Cometa/ProposalProcedures/HardForkInitiationAction.h index 40e199ab..b6bf8388 100644 --- a/lib/include/Cometa/ProposalProcedures/HardForkInitiationAction.h +++ b/lib/include/Cometa/ProposalProcedures/HardForkInitiationAction.h @@ -164,10 +164,38 @@ class HardForkInitiationAction */ bool operator!=(const HardForkInitiationAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static HardForkInitiationAction adopt(cardano_hard_fork_initiation_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_hard_fork_initiation_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_hard_fork_initiation_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_hard_fork_initiation_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProposalProcedures/InfoAction.h b/lib/include/Cometa/ProposalProcedures/InfoAction.h index 9cc91ba8..cc468913 100644 --- a/lib/include/Cometa/ProposalProcedures/InfoAction.h +++ b/lib/include/Cometa/ProposalProcedures/InfoAction.h @@ -132,10 +132,38 @@ class InfoAction */ bool operator!=(const InfoAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static InfoAction adopt(cardano_info_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_info_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_info_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_info_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProposalProcedures/NewConstitutionAction.h b/lib/include/Cometa/ProposalProcedures/NewConstitutionAction.h index 893a59a9..3ea3da1b 100644 --- a/lib/include/Cometa/ProposalProcedures/NewConstitutionAction.h +++ b/lib/include/Cometa/ProposalProcedures/NewConstitutionAction.h @@ -164,10 +164,38 @@ class NewConstitutionAction */ bool operator!=(const NewConstitutionAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static NewConstitutionAction adopt(cardano_new_constitution_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_new_constitution_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_new_constitution_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_new_constitution_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProposalProcedures/NoConfidenceAction.h b/lib/include/Cometa/ProposalProcedures/NoConfidenceAction.h index 57a33220..6d6939d1 100644 --- a/lib/include/Cometa/ProposalProcedures/NoConfidenceAction.h +++ b/lib/include/Cometa/ProposalProcedures/NoConfidenceAction.h @@ -150,10 +150,38 @@ class NoConfidenceAction */ bool operator!=(const NoConfidenceAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static NoConfidenceAction adopt(cardano_no_confidence_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_no_confidence_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_no_confidence_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_no_confidence_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProposalProcedures/ParameterChangeAction.h b/lib/include/Cometa/ProposalProcedures/ParameterChangeAction.h index 94ea1ee7..22ec7a52 100644 --- a/lib/include/Cometa/ProposalProcedures/ParameterChangeAction.h +++ b/lib/include/Cometa/ProposalProcedures/ParameterChangeAction.h @@ -181,10 +181,38 @@ class ParameterChangeAction */ bool operator!=(const ParameterChangeAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ParameterChangeAction adopt(cardano_parameter_change_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_parameter_change_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_parameter_change_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_parameter_change_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProposalProcedures/ProposalProcedure.h b/lib/include/Cometa/ProposalProcedures/ProposalProcedure.h index e924300e..c78c0eee 100644 --- a/lib/include/Cometa/ProposalProcedures/ProposalProcedure.h +++ b/lib/include/Cometa/ProposalProcedures/ProposalProcedure.h @@ -294,10 +294,38 @@ class ProposalProcedure */ bool operator!=(const ProposalProcedure& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProposalProcedure adopt(cardano_proposal_procedure_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_proposal_procedure_t* nativeHandle() noexcept; - /** @brief Allows proposal collections to copy their elements. */ - friend class ProposalProcedureSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_proposal_procedure_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_proposal_procedure_t* release() noexcept; + + private: /** * @brief Adopts an owned proposal. diff --git a/lib/include/Cometa/ProposalProcedures/ProposalProcedureSet.h b/lib/include/Cometa/ProposalProcedures/ProposalProcedureSet.h index 31cfe9b6..3a17886c 100644 --- a/lib/include/Cometa/ProposalProcedures/ProposalProcedureSet.h +++ b/lib/include/Cometa/ProposalProcedures/ProposalProcedureSet.h @@ -478,6 +478,45 @@ class ProposalProcedureSet m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProposalProcedureSet adopt(cardano_proposal_procedure_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_proposal_procedure_set_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_proposal_procedure_set_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_proposal_procedure_set_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -495,12 +534,6 @@ class ProposalProcedureSet private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/ProposalProcedures/TreasuryWithdrawalsAction.h b/lib/include/Cometa/ProposalProcedures/TreasuryWithdrawalsAction.h index 5ae328fb..b52919d9 100644 --- a/lib/include/Cometa/ProposalProcedures/TreasuryWithdrawalsAction.h +++ b/lib/include/Cometa/ProposalProcedures/TreasuryWithdrawalsAction.h @@ -164,10 +164,38 @@ class TreasuryWithdrawalsAction */ bool operator!=(const TreasuryWithdrawalsAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TreasuryWithdrawalsAction adopt(cardano_treasury_withdrawals_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_treasury_withdrawals_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_treasury_withdrawals_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_treasury_withdrawals_action_t* release() noexcept; + + private: /** @brief Allows governance actions to copy treasury withdrawal actions. */ diff --git a/lib/include/Cometa/ProposalProcedures/UpdateCommitteeAction.h b/lib/include/Cometa/ProposalProcedures/UpdateCommitteeAction.h index 583989aa..fea28a17 100644 --- a/lib/include/Cometa/ProposalProcedures/UpdateCommitteeAction.h +++ b/lib/include/Cometa/ProposalProcedures/UpdateCommitteeAction.h @@ -192,10 +192,38 @@ class UpdateCommitteeAction */ bool operator!=(const UpdateCommitteeAction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static UpdateCommitteeAction adopt(cardano_update_committee_action_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_update_committee_action_t* nativeHandle() noexcept; - /** @brief Allows proposal procedures to copy this value. */ - friend class ProposalProcedure; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_update_committee_action_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_update_committee_action_t* release() noexcept; + + private: /** * @brief Adopts an owned action. diff --git a/lib/include/Cometa/ProtocolParams/CostModel.h b/lib/include/Cometa/ProtocolParams/CostModel.h index c54e2941..046221e8 100644 --- a/lib/include/Cometa/ProtocolParams/CostModel.h +++ b/lib/include/Cometa/ProtocolParams/CostModel.h @@ -178,10 +178,38 @@ class CostModel */ bool operator!=(const CostModel& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CostModel adopt(cardano_cost_model_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_cost_model_t* nativeHandle() noexcept; - /** @brief Allows CostModels to copy model values. */ - friend class CostModels; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_cost_model_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_cost_model_t* release() noexcept; + + private: /** * @brief Adopts an owned model. diff --git a/lib/include/Cometa/ProtocolParams/CostModels.h b/lib/include/Cometa/ProtocolParams/CostModels.h index eb3b0f92..6ba455c7 100644 --- a/lib/include/Cometa/ProtocolParams/CostModels.h +++ b/lib/include/Cometa/ProtocolParams/CostModels.h @@ -242,12 +242,6 @@ class CostModels */ bool operator!=(const CostModels& other) const; - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; - - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; - public: /** @@ -477,6 +471,45 @@ class CostModels } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static CostModels adopt(cardano_costmdls_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_costmdls_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_costmdls_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_costmdls_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ diff --git a/lib/include/Cometa/ProtocolParams/DRepVotingThresholds.h b/lib/include/Cometa/ProtocolParams/DRepVotingThresholds.h index 3dcdf5f0..b5c46974 100644 --- a/lib/include/Cometa/ProtocolParams/DRepVotingThresholds.h +++ b/lib/include/Cometa/ProtocolParams/DRepVotingThresholds.h @@ -276,11 +276,36 @@ class DRepVotingThresholds */ bool operator!=(const DRepVotingThresholds& other) const; - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static DRepVotingThresholds adopt(cardano_drep_voting_thresholds_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_drep_voting_thresholds_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_drep_voting_thresholds_t* nativeHandle() const noexcept; - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_drep_voting_thresholds_t* release() noexcept; private: diff --git a/lib/include/Cometa/ProtocolParams/ExUnitPrices.h b/lib/include/Cometa/ProtocolParams/ExUnitPrices.h index c41be4d3..ec7893bc 100644 --- a/lib/include/Cometa/ProtocolParams/ExUnitPrices.h +++ b/lib/include/Cometa/ProtocolParams/ExUnitPrices.h @@ -162,11 +162,36 @@ class ExUnitPrices */ bool operator!=(const ExUnitPrices& other) const; - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ExUnitPrices adopt(cardano_ex_unit_prices_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_ex_unit_prices_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_ex_unit_prices_t* nativeHandle() const noexcept; - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_ex_unit_prices_t* release() noexcept; private: diff --git a/lib/include/Cometa/ProtocolParams/PoolVotingThresholds.h b/lib/include/Cometa/ProtocolParams/PoolVotingThresholds.h index 7ddf6c8d..8042c9d9 100644 --- a/lib/include/Cometa/ProtocolParams/PoolVotingThresholds.h +++ b/lib/include/Cometa/ProtocolParams/PoolVotingThresholds.h @@ -206,11 +206,36 @@ class PoolVotingThresholds */ bool operator!=(const PoolVotingThresholds& other) const; - /** @brief Allows protocol updates to copy native values. */ - friend class ProtocolParamUpdate; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PoolVotingThresholds adopt(cardano_pool_voting_thresholds_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_pool_voting_thresholds_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_pool_voting_thresholds_t* nativeHandle() const noexcept; - /** @brief Allows protocol parameters to copy native values. */ - friend class ProtocolParameters; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_pool_voting_thresholds_t* release() noexcept; private: diff --git a/lib/include/Cometa/ProtocolParams/ProposedParamUpdates.h b/lib/include/Cometa/ProtocolParams/ProposedParamUpdates.h index 4809232b..7d85aef5 100644 --- a/lib/include/Cometa/ProtocolParams/ProposedParamUpdates.h +++ b/lib/include/Cometa/ProtocolParams/ProposedParamUpdates.h @@ -179,9 +179,38 @@ class ProposedParamUpdates */ bool operator!=(const ProposedParamUpdates& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProposedParamUpdates adopt(cardano_proposed_param_updates_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_proposed_param_updates_t* nativeHandle() noexcept; - friend class Update; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_proposed_param_updates_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_proposed_param_updates_t* release() noexcept; + + private: /** * @brief Adopts an owned collection. diff --git a/lib/include/Cometa/ProtocolParams/ProtocolParamUpdate.h b/lib/include/Cometa/ProtocolParams/ProtocolParamUpdate.h index ed7039a0..bb856aef 100644 --- a/lib/include/Cometa/ProtocolParams/ProtocolParamUpdate.h +++ b/lib/include/Cometa/ProtocolParams/ProtocolParamUpdate.h @@ -887,11 +887,36 @@ class ProtocolParamUpdate */ bool operator!=(const ProtocolParamUpdate& other) const; - /** @brief Allows the proposed-update map to access native values. */ - friend class ProposedParamUpdates; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProtocolParamUpdate adopt(cardano_protocol_param_update_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_protocol_param_update_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_protocol_param_update_t* nativeHandle() const noexcept; - /** @brief Allows parameter change actions to copy parameter updates. */ - friend class ParameterChangeAction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_protocol_param_update_t* release() noexcept; private: diff --git a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h index 5769a119..12eeae8a 100644 --- a/lib/include/Cometa/ProtocolParams/ProtocolParameters.h +++ b/lib/include/Cometa/ProtocolParams/ProtocolParameters.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -46,12 +45,6 @@ struct cardano_protocol_parameters_t; namespace Cometa { -class Transaction; -class SubTransaction; -class Value; -struct ImplicitCoin; -struct TransactionBalanceRequest; - /** * @brief A snapshot of a network's ledger limits, fees, deposits, and governance settings. * @@ -799,46 +792,46 @@ class ProtocolParameters */ bool operator!=(const ProtocolParameters& other) const; - private: - - /** @brief Grants computeTransactionFee access to stored protocol parameters. */ - friend std::uint64_t computeTransactionFee(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); - - /** @brief Grants computeScriptRefFee access to stored protocol parameters. */ - friend std::uint64_t computeScriptRefFee(const UtxoList& resolvedInputs, const ProtocolParameters& parameters); - - /** @brief Grants computeImplicitCoin access to stored protocol parameters. */ - friend ImplicitCoin computeImplicitCoin(const Transaction& transaction, const ProtocolParameters& parameters); - - /** @brief Grants computeImplicitCoin access to stored protocol parameters. */ - friend ImplicitCoin computeImplicitCoin(const SubTransaction& transaction, const ProtocolParameters& parameters); - - /** @brief Grants computeTransactionImbalance access to stored protocol parameters. */ - friend Value computeTransactionImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); - - /** @brief Grants computeSubTransactionImbalance access to stored protocol parameters. */ - friend Value computeSubTransactionImbalance(const SubTransaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + public: - /** @brief Grants computeTransactionBatchImbalance access to stored protocol parameters. */ - friend Value computeTransactionBatchImbalance(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ProtocolParameters adopt(cardano_protocol_parameters_t* value); - /** @brief Grants isTransactionBalanced access to stored protocol parameters. */ - friend bool isTransactionBalanced(const Transaction& transaction, const UtxoList& resolvedInputs, const ProtocolParameters& parameters); + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_protocol_parameters_t* nativeHandle() noexcept; - /** @brief Grants balanceTransaction access to stored protocol parameters. */ - friend Transaction balanceTransaction(const TransactionBalanceRequest& request); + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_protocol_parameters_t* nativeHandle() const noexcept; - /** @brief Grants copyProtocolParametersToNative access to stored protocol parameters. */ - friend cardano_protocol_parameters_t* copyProtocolParametersToNative(const ProtocolParameters& parameters); + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_protocol_parameters_t* release() noexcept; - /** @brief Grants copyProtocolParametersFromNative access to stored protocol parameters. */ - friend ProtocolParameters copyProtocolParametersFromNative(const cardano_protocol_parameters_t* parameters); + private: - /** @brief Allows transaction builders to retain protocol parameters. */ - friend class TransactionBuilder; + /** + * @brief Takes ownership of a validated native reference. + * @param value The owned non-null reference. + */ + explicit ProtocolParameters(cardano_protocol_parameters_t* value) noexcept; - /** @brief Allows sub-transaction builders to retain protocol parameters. */ - friend class SubTransactionBuilder; + private: /** * @brief Gets the stored parameters. diff --git a/lib/include/Cometa/ProtocolParams/Update.h b/lib/include/Cometa/ProtocolParams/Update.h index 1b41beb1..0e0cd273 100644 --- a/lib/include/Cometa/ProtocolParams/Update.h +++ b/lib/include/Cometa/ProtocolParams/Update.h @@ -162,10 +162,38 @@ class Update */ bool operator!=(const Update& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Update adopt(cardano_update_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_update_t* nativeHandle() noexcept; - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_update_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_update_t* release() noexcept; + + private: /** * @brief Adopts an owned update. diff --git a/lib/include/Cometa/Scripts/NativeScripts/NativeScript.h b/lib/include/Cometa/Scripts/NativeScripts/NativeScript.h index 5e002097..3b6e402f 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/NativeScript.h +++ b/lib/include/Cometa/Scripts/NativeScripts/NativeScript.h @@ -347,16 +347,38 @@ class NativeScript */ bool operator!=(const NativeScript& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static NativeScript adopt(cardano_native_script_t* value); - /** @brief Allows Script to copy and validate native script payloads. */ - friend class Script; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_native_script_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_native_script_t* nativeHandle() const noexcept; - /** @brief Allows NativeScriptList to copy script elements. */ - friend class NativeScriptList; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_native_script_t* release() noexcept; - /** @brief Allows witness sets to copy native scripts. */ - friend class NativeScriptSet; + private: /** * @brief Takes ownership of an existing reference. @@ -377,14 +399,6 @@ class NativeScript cardano_native_script_t* checked() const; private: - - /** - * @brief Checks nested requirements before exposing decoded values. - * - * @throws std::invalid_argument A key hash is not 28 bytes. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/Scripts/NativeScripts/NativeScriptList.h b/lib/include/Cometa/Scripts/NativeScripts/NativeScriptList.h index 1343a8fc..da75fc21 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/NativeScriptList.h +++ b/lib/include/Cometa/Scripts/NativeScripts/NativeScriptList.h @@ -527,6 +527,45 @@ class NativeScriptList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static NativeScriptList adopt(cardano_native_script_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_native_script_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_native_script_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_native_script_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -544,21 +583,6 @@ class NativeScriptList private: - /** @brief Allows AuxiliaryData to copy attached values. */ - friend class AuxiliaryData; - - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; - - /** @brief Allows ScriptAll to copy and validate child scripts. */ - friend class ScriptAll; - - /** @brief Allows ScriptAny to copy and validate child scripts. */ - friend class ScriptAny; - - /** @brief Allows ScriptNOfK to copy and validate child scripts. */ - friend class ScriptNOfK; - /** * @brief Takes ownership of an existing reference. * @@ -578,14 +602,6 @@ class NativeScriptList cardano_native_script_list_t* checked() const; private: - - /** - * @brief Checks nested requirements before exposing decoded values. - * - * @throws std::invalid_argument A key hash is not 28 bytes. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptAll.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptAll.h index 18907c88..85b084cc 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptAll.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptAll.h @@ -199,10 +199,38 @@ class ScriptAll */ bool operator!=(const ScriptAll& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptAll adopt(cardano_script_all_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_all_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_all_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_all_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptAny.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptAny.h index f3cdfe5e..8741a9ad 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptAny.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptAny.h @@ -199,10 +199,38 @@ class ScriptAny */ bool operator!=(const ScriptAny& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptAny adopt(cardano_script_any_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_any_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_any_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_any_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidAfter.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidAfter.h index 9b44b1e7..7353be4a 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidAfter.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidAfter.h @@ -189,10 +189,38 @@ class ScriptInvalidAfter */ bool operator!=(const ScriptInvalidAfter& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptInvalidAfter adopt(cardano_script_invalid_after_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_invalid_after_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_invalid_after_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_invalid_after_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidBefore.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidBefore.h index ad48ac7e..9b6f4c56 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidBefore.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptInvalidBefore.h @@ -189,10 +189,38 @@ class ScriptInvalidBefore */ bool operator!=(const ScriptInvalidBefore& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptInvalidBefore adopt(cardano_script_invalid_before_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_invalid_before_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_invalid_before_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_invalid_before_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptNOfK.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptNOfK.h index 7234c861..9523ef33 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptNOfK.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptNOfK.h @@ -214,10 +214,38 @@ class ScriptNOfK */ bool operator!=(const ScriptNOfK& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptNOfK adopt(cardano_script_n_of_k_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_n_of_k_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_n_of_k_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_n_of_k_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptPubkey.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptPubkey.h index 977a84b2..8dc5ecc9 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptPubkey.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptPubkey.h @@ -191,10 +191,38 @@ class ScriptPubkey */ bool operator!=(const ScriptPubkey& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptPubkey adopt(cardano_script_pubkey_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_pubkey_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_pubkey_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_pubkey_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/NativeScripts/ScriptRequireGuard.h b/lib/include/Cometa/Scripts/NativeScripts/ScriptRequireGuard.h index 02835474..3d57b2b3 100644 --- a/lib/include/Cometa/Scripts/NativeScripts/ScriptRequireGuard.h +++ b/lib/include/Cometa/Scripts/NativeScripts/ScriptRequireGuard.h @@ -191,10 +191,38 @@ class ScriptRequireGuard */ bool operator!=(const ScriptRequireGuard& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static ScriptRequireGuard adopt(cardano_script_require_guard_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_require_guard_t* nativeHandle() noexcept; - /** @brief Allows NativeScript to copy this script variant. */ - friend class NativeScript; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_require_guard_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_require_guard_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV1Script.h b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV1Script.h index ed7da395..6cab8449 100644 --- a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV1Script.h +++ b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV1Script.h @@ -217,16 +217,38 @@ class PlutusV1Script */ bool operator!=(const PlutusV1Script& other) const; - private: + public: - /** @brief Allows Script to copy this script variant. */ - friend class Script; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV1Script adopt(cardano_plutus_v1_script_t* value); - /** @brief Allows the auxiliary script list to copy script values. */ - friend class PlutusV1ScriptList; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_plutus_v1_script_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy Plutus scripts. */ - friend class PlutusV1ScriptSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v1_script_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_plutus_v1_script_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV2Script.h b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV2Script.h index ea3965d3..501fa866 100644 --- a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV2Script.h +++ b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV2Script.h @@ -217,16 +217,38 @@ class PlutusV2Script */ bool operator!=(const PlutusV2Script& other) const; - private: + public: - /** @brief Allows Script to copy this script variant. */ - friend class Script; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV2Script adopt(cardano_plutus_v2_script_t* value); - /** @brief Allows the auxiliary script list to copy script values. */ - friend class PlutusV2ScriptList; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_plutus_v2_script_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy Plutus scripts. */ - friend class PlutusV2ScriptSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v2_script_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_plutus_v2_script_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV3Script.h b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV3Script.h index 1f49967c..02feda22 100644 --- a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV3Script.h +++ b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV3Script.h @@ -217,16 +217,38 @@ class PlutusV3Script */ bool operator!=(const PlutusV3Script& other) const; - private: + public: - /** @brief Allows Script to copy this script variant. */ - friend class Script; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV3Script adopt(cardano_plutus_v3_script_t* value); - /** @brief Allows the auxiliary script list to copy script values. */ - friend class PlutusV3ScriptList; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_plutus_v3_script_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy Plutus scripts. */ - friend class PlutusV3ScriptSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v3_script_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_plutus_v3_script_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV4Script.h b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV4Script.h index 5394a7a1..b0d89234 100644 --- a/lib/include/Cometa/Scripts/PlutusScripts/PlutusV4Script.h +++ b/lib/include/Cometa/Scripts/PlutusScripts/PlutusV4Script.h @@ -217,16 +217,38 @@ class PlutusV4Script */ bool operator!=(const PlutusV4Script& other) const; - private: + public: - /** @brief Allows Script to copy this script variant. */ - friend class Script; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV4Script adopt(cardano_plutus_v4_script_t* value); - /** @brief Allows the auxiliary script list to copy script values. */ - friend class PlutusV4ScriptList; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_plutus_v4_script_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy Plutus scripts. */ - friend class PlutusV4ScriptSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v4_script_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_plutus_v4_script_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/Scripts/Script.h b/lib/include/Cometa/Scripts/Script.h index bbb709f6..9b20f044 100644 --- a/lib/include/Cometa/Scripts/Script.h +++ b/lib/include/Cometa/Scripts/Script.h @@ -323,13 +323,38 @@ class Script */ bool operator!=(const Script& other) const; - private: + public: - /** @brief Allows WitnessSet to copy scripts. */ - friend class WitnessSet; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Script adopt(cardano_script_t* value); - /** @brief Allows TransactionOutput to copy components. */ - friend class TransactionOutput; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_script_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_script_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_script_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. @@ -349,11 +374,6 @@ class Script */ cardano_script_t* checked() const; - /** - * @brief Checks script payload invariants. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/Transaction/SubTransaction.h b/lib/include/Cometa/Transaction/SubTransaction.h index 498f21ee..ef20b37e 100644 --- a/lib/include/Cometa/Transaction/SubTransaction.h +++ b/lib/include/Cometa/Transaction/SubTransaction.h @@ -196,10 +196,38 @@ class SubTransaction */ bool operator!=(const SubTransaction& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static SubTransaction adopt(cardano_sub_transaction_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_sub_transaction_t* nativeHandle() noexcept; - /** @brief Allows sub-transaction sets to copy this value. */ - friend class SubTransactionSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_sub_transaction_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_sub_transaction_t* release() noexcept; + + private: /** * @brief Adopts an owned sub-transaction. diff --git a/lib/include/Cometa/Transaction/SubTransactionSet.h b/lib/include/Cometa/Transaction/SubTransactionSet.h index 233391b9..ad3f0b92 100644 --- a/lib/include/Cometa/Transaction/SubTransactionSet.h +++ b/lib/include/Cometa/Transaction/SubTransactionSet.h @@ -387,6 +387,39 @@ class SubTransactionSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static SubTransactionSet adopt(cardano_sub_transaction_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_sub_transaction_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_sub_transaction_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_sub_transaction_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -405,9 +438,6 @@ class SubTransactionSet private: - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned set. * @param value The owned set. diff --git a/lib/include/Cometa/Transaction/Transaction.h b/lib/include/Cometa/Transaction/Transaction.h index c66650ce..8531c5ae 100644 --- a/lib/include/Cometa/Transaction/Transaction.h +++ b/lib/include/Cometa/Transaction/Transaction.h @@ -306,6 +306,37 @@ class Transaction */ bool operator!=(const Transaction& other) const; + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Transaction adopt(cardano_transaction_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_transaction_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_transaction_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_transaction_t* release() noexcept; + private: /** diff --git a/lib/include/Cometa/TransactionBody/AccountBalanceInterval.h b/lib/include/Cometa/TransactionBody/AccountBalanceInterval.h index a139210b..3fd37244 100644 --- a/lib/include/Cometa/TransactionBody/AccountBalanceInterval.h +++ b/lib/include/Cometa/TransactionBody/AccountBalanceInterval.h @@ -169,10 +169,38 @@ class AccountBalanceInterval */ bool operator!=(const AccountBalanceInterval& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AccountBalanceInterval adopt(cardano_account_balance_interval_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_account_balance_interval_t* nativeHandle() noexcept; - /** @brief Allows account balance maps to copy intervals. */ - friend class AccountBalanceIntervalsMap; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_account_balance_interval_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_account_balance_interval_t* release() noexcept; + + private: /** * @brief Adopts an owned interval. diff --git a/lib/include/Cometa/TransactionBody/AccountBalanceIntervalsMap.h b/lib/include/Cometa/TransactionBody/AccountBalanceIntervalsMap.h index a99c3a90..291f75bd 100644 --- a/lib/include/Cometa/TransactionBody/AccountBalanceIntervalsMap.h +++ b/lib/include/Cometa/TransactionBody/AccountBalanceIntervalsMap.h @@ -475,6 +475,45 @@ class AccountBalanceIntervalsMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static AccountBalanceIntervalsMap adopt(cardano_account_balance_intervals_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_account_balance_intervals_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_account_balance_intervals_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_account_balance_intervals_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -502,12 +541,6 @@ class AccountBalanceIntervalsMap private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned map. * @param value The owned map. diff --git a/lib/include/Cometa/TransactionBody/DirectDepositMap.h b/lib/include/Cometa/TransactionBody/DirectDepositMap.h index bb99e70f..0d43e89e 100644 --- a/lib/include/Cometa/TransactionBody/DirectDepositMap.h +++ b/lib/include/Cometa/TransactionBody/DirectDepositMap.h @@ -481,6 +481,45 @@ class DirectDepositMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static DirectDepositMap adopt(cardano_direct_deposit_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_direct_deposit_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_direct_deposit_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_direct_deposit_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -508,12 +547,6 @@ class DirectDepositMap private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned map. * @param value The owned map. diff --git a/lib/include/Cometa/TransactionBody/GuardSet.h b/lib/include/Cometa/TransactionBody/GuardSet.h index 69ce98f8..c727997c 100644 --- a/lib/include/Cometa/TransactionBody/GuardSet.h +++ b/lib/include/Cometa/TransactionBody/GuardSet.h @@ -376,6 +376,39 @@ class GuardSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static GuardSet adopt(cardano_guard_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_guard_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_guard_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_guard_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -394,15 +427,6 @@ class GuardSet private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/TransactionBody/RequiredGuardsMap.h b/lib/include/Cometa/TransactionBody/RequiredGuardsMap.h index d7511cde..508f7505 100644 --- a/lib/include/Cometa/TransactionBody/RequiredGuardsMap.h +++ b/lib/include/Cometa/TransactionBody/RequiredGuardsMap.h @@ -474,6 +474,45 @@ class RequiredGuardsMap } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static RequiredGuardsMap adopt(cardano_required_guards_map_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_required_guards_map_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_required_guards_map_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_required_guards_map_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -501,12 +540,6 @@ class RequiredGuardsMap private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned map. * @param value The owned map. diff --git a/lib/include/Cometa/TransactionBody/SubTransactionBody.h b/lib/include/Cometa/TransactionBody/SubTransactionBody.h index b87ef7e4..20ba49f9 100644 --- a/lib/include/Cometa/TransactionBody/SubTransactionBody.h +++ b/lib/include/Cometa/TransactionBody/SubTransactionBody.h @@ -386,10 +386,38 @@ class SubTransactionBody */ bool operator!=(const SubTransactionBody& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static SubTransactionBody adopt(cardano_sub_transaction_body_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_sub_transaction_body_t* nativeHandle() noexcept; - /** @brief Allows sub-transactions to copy this value. */ - friend class SubTransaction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_sub_transaction_body_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_sub_transaction_body_t* release() noexcept; + + private: /** * @brief Adopts an owned body. diff --git a/lib/include/Cometa/TransactionBody/TransactionBody.h b/lib/include/Cometa/TransactionBody/TransactionBody.h index db642edb..5df52587 100644 --- a/lib/include/Cometa/TransactionBody/TransactionBody.h +++ b/lib/include/Cometa/TransactionBody/TransactionBody.h @@ -494,10 +494,38 @@ class TransactionBody */ bool operator!=(const TransactionBody& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionBody adopt(cardano_transaction_body_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_transaction_body_t* nativeHandle() noexcept; - /** @brief Allows transactions to copy this value. */ - friend class Transaction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_transaction_body_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_transaction_body_t* release() noexcept; + + private: /** * @brief Adopts an owned body. diff --git a/lib/include/Cometa/TransactionBody/TransactionInput.h b/lib/include/Cometa/TransactionBody/TransactionInput.h index ac16ea8c..775303ef 100644 --- a/lib/include/Cometa/TransactionBody/TransactionInput.h +++ b/lib/include/Cometa/TransactionBody/TransactionInput.h @@ -234,13 +234,38 @@ class TransactionInput */ bool operator>=(const TransactionInput& other) const; - private: + public: - /** @brief Allows Utxo to copy and validate components. */ - friend class Utxo; + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionInput adopt(cardano_transaction_input_t* value); - /** @brief Allows TransactionInputSet to copy and validate components. */ - friend class TransactionInputSet; + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_transaction_input_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_transaction_input_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_transaction_input_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. @@ -260,11 +285,6 @@ class TransactionInput */ cardano_transaction_input_t* checked() const; - /** - * @brief Checks the decoded value invariants. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/TransactionBody/TransactionInputSet.h b/lib/include/Cometa/TransactionBody/TransactionInputSet.h index 584a869c..43df0139 100644 --- a/lib/include/Cometa/TransactionBody/TransactionInputSet.h +++ b/lib/include/Cometa/TransactionBody/TransactionInputSet.h @@ -407,6 +407,39 @@ class TransactionInputSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionInputSet adopt(cardano_transaction_input_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_transaction_input_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_transaction_input_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_transaction_input_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -432,12 +465,6 @@ class TransactionInputSet private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts one owned native set. * diff --git a/lib/include/Cometa/TransactionBody/TransactionOutput.h b/lib/include/Cometa/TransactionBody/TransactionOutput.h index 247683bd..79103205 100644 --- a/lib/include/Cometa/TransactionBody/TransactionOutput.h +++ b/lib/include/Cometa/TransactionBody/TransactionOutput.h @@ -220,16 +220,38 @@ class TransactionOutput */ bool operator!=(const TransactionOutput& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionOutput adopt(cardano_transaction_output_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_transaction_output_t* nativeHandle() noexcept; - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_transaction_output_t* nativeHandle() const noexcept; - /** @brief Allows Utxo to copy and validate components. */ - friend class Utxo; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_transaction_output_t* release() noexcept; - /** @brief Allows TransactionOutputList to copy and validate components. */ - friend class TransactionOutputList; + private: /** * @brief Takes ownership of an existing reference. @@ -249,11 +271,6 @@ class TransactionOutput */ cardano_transaction_output_t* checked() const; - /** - * @brief Checks the decoded value invariants. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/TransactionBody/TransactionOutputList.h b/lib/include/Cometa/TransactionBody/TransactionOutputList.h index f9851e33..0d80aa8d 100644 --- a/lib/include/Cometa/TransactionBody/TransactionOutputList.h +++ b/lib/include/Cometa/TransactionBody/TransactionOutputList.h @@ -509,6 +509,45 @@ class TransactionOutputList m_mutableAccess = true; } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static TransactionOutputList adopt(cardano_transaction_output_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_transaction_output_list_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_transaction_output_list_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_transaction_output_list_t* release(); + private: /** @brief Copies native elements into the C++ sequence on first access. */ @@ -526,12 +565,6 @@ class TransactionOutputList private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Takes ownership of an existing reference. * @@ -550,13 +583,6 @@ class TransactionOutputList */ cardano_transaction_output_list_t* checked() const; - /** - * @brief Checks nested output values before exposing decoded values. - * - * @throws std::invalid_argument An output violates the value constraints. - */ - void validate() const; - private: /** @brief The owned reference, or null after a move. */ diff --git a/lib/include/Cometa/TransactionBody/Value.h b/lib/include/Cometa/TransactionBody/Value.h index 7d7025c8..44e32036 100644 --- a/lib/include/Cometa/TransactionBody/Value.h +++ b/lib/include/Cometa/TransactionBody/Value.h @@ -371,10 +371,38 @@ class Value */ bool operator!=(const Value& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Value adopt(cardano_value_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_value_t* nativeHandle() noexcept; - /** @brief Allows TransactionOutput to copy output values. */ - friend class TransactionOutput; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_value_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_value_t* release() noexcept; + + private: /** * @brief Takes ownership of an existing reference. diff --git a/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h b/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h index 6d9c0e03..0f053720 100644 --- a/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h +++ b/lib/include/Cometa/TransactionBuilder/SubTransactionBuilder.h @@ -622,6 +622,22 @@ class SubTransactionBuilder /** @brief A builder cannot be copy assigned. */ SubTransactionBuilder& operator=(const SubTransactionBuilder&) = delete; + public: + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_sub_tx_builder_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_sub_tx_builder_t* nativeHandle() const noexcept; + private: /** diff --git a/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h b/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h index 38590727..a1f3de42 100644 --- a/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h +++ b/lib/include/Cometa/TransactionBuilder/TransactionBuilder.h @@ -741,6 +741,22 @@ class TransactionBuilder /** @brief A builder cannot be copy assigned. */ TransactionBuilder& operator=(const TransactionBuilder&) = delete; + public: + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_tx_builder_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_tx_builder_t* nativeHandle() const noexcept; + private: /** diff --git a/lib/include/Cometa/VotingProcedures/Voter.h b/lib/include/Cometa/VotingProcedures/Voter.h index 1b3f0a86..1ba452e3 100644 --- a/lib/include/Cometa/VotingProcedures/Voter.h +++ b/lib/include/Cometa/VotingProcedures/Voter.h @@ -170,13 +170,38 @@ class Voter */ bool operator<(const Voter& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Voter adopt(cardano_voter_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_voter_t* nativeHandle() noexcept; - /** @brief Allows transactions to use this value. */ - friend class Transaction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_voter_t* nativeHandle() const noexcept; - /** @brief Allows voting maps to transfer independent values. */ - friend class VotingProcedures; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_voter_t* release() noexcept; + + private: /** * @brief Adopts an owned voter. diff --git a/lib/include/Cometa/VotingProcedures/VotingProcedure.h b/lib/include/Cometa/VotingProcedures/VotingProcedure.h index e892b95c..a410fd5d 100644 --- a/lib/include/Cometa/VotingProcedures/VotingProcedure.h +++ b/lib/include/Cometa/VotingProcedures/VotingProcedure.h @@ -164,10 +164,38 @@ class VotingProcedure */ bool operator!=(const VotingProcedure& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VotingProcedure adopt(cardano_voting_procedure_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_voting_procedure_t* nativeHandle() noexcept; - /** @brief Allows voting maps to transfer independent values. */ - friend class VotingProcedures; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_voting_procedure_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_voting_procedure_t* release() noexcept; + + private: /** * @brief Adopts an owned voting procedure. diff --git a/lib/include/Cometa/VotingProcedures/VotingProcedures.h b/lib/include/Cometa/VotingProcedures/VotingProcedures.h index 02973e93..3312681c 100644 --- a/lib/include/Cometa/VotingProcedures/VotingProcedures.h +++ b/lib/include/Cometa/VotingProcedures/VotingProcedures.h @@ -472,6 +472,45 @@ class VotingProcedures } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VotingProcedures adopt(cardano_voting_procedures_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_voting_procedures_t* nativeHandle(); + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + const cardano_voting_procedures_t* nativeHandle() const; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + * @throws std::bad_alloc Synchronizing edited elements cannot allocate memory. + * @throws Error Edited elements cannot be represented by the native collection. + */ + cardano_voting_procedures_t* release(); + private: /** @brief Initializes the C++ entries on first access. */ @@ -508,12 +547,6 @@ class VotingProcedures private: - /** @brief Allows sub-transaction bodies to copy this value. */ - friend class SubTransactionBody; - - /** @brief Allows transaction bodies to copy this value. */ - friend class TransactionBody; - /** * @brief Adopts an owned voting map. * @param value The owned map. diff --git a/lib/include/Cometa/WitnessSet/BootstrapWitness.h b/lib/include/Cometa/WitnessSet/BootstrapWitness.h index 10ca677b..5f0678a4 100644 --- a/lib/include/Cometa/WitnessSet/BootstrapWitness.h +++ b/lib/include/Cometa/WitnessSet/BootstrapWitness.h @@ -191,10 +191,38 @@ class BootstrapWitness */ bool operator!=(const BootstrapWitness& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static BootstrapWitness adopt(cardano_bootstrap_witness_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_bootstrap_witness_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy their elements. */ - friend class BootstrapWitnessSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bootstrap_witness_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_bootstrap_witness_t* release() noexcept; + + private: /** * @brief Adopts an owned witness. diff --git a/lib/include/Cometa/WitnessSet/BootstrapWitnessSet.h b/lib/include/Cometa/WitnessSet/BootstrapWitnessSet.h index 8f28fbff..34a8ee51 100644 --- a/lib/include/Cometa/WitnessSet/BootstrapWitnessSet.h +++ b/lib/include/Cometa/WitnessSet/BootstrapWitnessSet.h @@ -376,6 +376,39 @@ class BootstrapWitnessSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static BootstrapWitnessSet adopt(cardano_bootstrap_witness_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_bootstrap_witness_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_bootstrap_witness_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_bootstrap_witness_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -394,9 +427,6 @@ class BootstrapWitnessSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/NativeScriptSet.h b/lib/include/Cometa/WitnessSet/NativeScriptSet.h index 451e8e4a..507c5d66 100644 --- a/lib/include/Cometa/WitnessSet/NativeScriptSet.h +++ b/lib/include/Cometa/WitnessSet/NativeScriptSet.h @@ -376,6 +376,39 @@ class NativeScriptSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static NativeScriptSet adopt(cardano_native_script_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_native_script_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_native_script_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_native_script_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -394,9 +427,6 @@ class NativeScriptSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/PlutusDataSet.h b/lib/include/Cometa/WitnessSet/PlutusDataSet.h index 653c1ab7..b30bc3fa 100644 --- a/lib/include/Cometa/WitnessSet/PlutusDataSet.h +++ b/lib/include/Cometa/WitnessSet/PlutusDataSet.h @@ -376,6 +376,39 @@ class PlutusDataSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusDataSet adopt(cardano_plutus_data_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_data_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_data_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_data_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -394,9 +427,6 @@ class PlutusDataSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/PlutusV1ScriptSet.h b/lib/include/Cometa/WitnessSet/PlutusV1ScriptSet.h index a163d84b..d1bac366 100644 --- a/lib/include/Cometa/WitnessSet/PlutusV1ScriptSet.h +++ b/lib/include/Cometa/WitnessSet/PlutusV1ScriptSet.h @@ -377,6 +377,39 @@ class PlutusV1ScriptSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV1ScriptSet adopt(cardano_plutus_v1_script_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v1_script_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v1_script_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v1_script_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -395,9 +428,6 @@ class PlutusV1ScriptSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/PlutusV2ScriptSet.h b/lib/include/Cometa/WitnessSet/PlutusV2ScriptSet.h index c258beee..697529af 100644 --- a/lib/include/Cometa/WitnessSet/PlutusV2ScriptSet.h +++ b/lib/include/Cometa/WitnessSet/PlutusV2ScriptSet.h @@ -377,6 +377,39 @@ class PlutusV2ScriptSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV2ScriptSet adopt(cardano_plutus_v2_script_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v2_script_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v2_script_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v2_script_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -395,9 +428,6 @@ class PlutusV2ScriptSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/PlutusV3ScriptSet.h b/lib/include/Cometa/WitnessSet/PlutusV3ScriptSet.h index bf7b8e8f..49ec986e 100644 --- a/lib/include/Cometa/WitnessSet/PlutusV3ScriptSet.h +++ b/lib/include/Cometa/WitnessSet/PlutusV3ScriptSet.h @@ -377,6 +377,39 @@ class PlutusV3ScriptSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV3ScriptSet adopt(cardano_plutus_v3_script_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v3_script_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v3_script_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v3_script_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -395,9 +428,6 @@ class PlutusV3ScriptSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/PlutusV4ScriptSet.h b/lib/include/Cometa/WitnessSet/PlutusV4ScriptSet.h index 219cb056..ea0620d7 100644 --- a/lib/include/Cometa/WitnessSet/PlutusV4ScriptSet.h +++ b/lib/include/Cometa/WitnessSet/PlutusV4ScriptSet.h @@ -377,6 +377,39 @@ class PlutusV4ScriptSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static PlutusV4ScriptSet adopt(cardano_plutus_v4_script_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v4_script_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_plutus_v4_script_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_plutus_v4_script_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -395,9 +428,6 @@ class PlutusV4ScriptSet private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/Redeemer.h b/lib/include/Cometa/WitnessSet/Redeemer.h index d71ac3d1..e1a5f84d 100644 --- a/lib/include/Cometa/WitnessSet/Redeemer.h +++ b/lib/include/Cometa/WitnessSet/Redeemer.h @@ -190,10 +190,38 @@ class Redeemer */ bool operator!=(const Redeemer& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static Redeemer adopt(cardano_redeemer_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_redeemer_t* nativeHandle() noexcept; - /** @brief Allows redeemer lists to copy their elements. */ - friend class RedeemerList; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_redeemer_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_redeemer_t* release() noexcept; + + private: /** * @brief Adopts an owned redeemer. diff --git a/lib/include/Cometa/WitnessSet/RedeemerList.h b/lib/include/Cometa/WitnessSet/RedeemerList.h index a01bdf05..c732e49c 100644 --- a/lib/include/Cometa/WitnessSet/RedeemerList.h +++ b/lib/include/Cometa/WitnessSet/RedeemerList.h @@ -373,6 +373,39 @@ class RedeemerList } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static RedeemerList adopt(cardano_redeemer_list_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_redeemer_list_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_redeemer_list_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_redeemer_list_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -391,9 +424,6 @@ class RedeemerList private: - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/VkeyWitness.h b/lib/include/Cometa/WitnessSet/VkeyWitness.h index 4d7446dc..837d05a6 100644 --- a/lib/include/Cometa/WitnessSet/VkeyWitness.h +++ b/lib/include/Cometa/WitnessSet/VkeyWitness.h @@ -170,10 +170,38 @@ class VkeyWitness */ bool operator!=(const VkeyWitness& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VkeyWitness adopt(cardano_vkey_witness_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_vkey_witness_t* nativeHandle() noexcept; - /** @brief Allows witness sets to copy their elements. */ - friend class VkeyWitnessSet; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_vkey_witness_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_vkey_witness_t* release() noexcept; + + private: /** * @brief Adopts an owned witness. diff --git a/lib/include/Cometa/WitnessSet/VkeyWitnessSet.h b/lib/include/Cometa/WitnessSet/VkeyWitnessSet.h index 5216e96c..3053400d 100644 --- a/lib/include/Cometa/WitnessSet/VkeyWitnessSet.h +++ b/lib/include/Cometa/WitnessSet/VkeyWitnessSet.h @@ -382,6 +382,39 @@ class VkeyWitnessSet } } + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static VkeyWitnessSet adopt(cardano_vkey_witness_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_vkey_witness_set_t* nativeHandle() noexcept; + + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_vkey_witness_set_t* nativeHandle() const noexcept; + + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + * @remark Invalidates all collection iterators and element references. Finish native access before using the collection again. + */ + cardano_vkey_witness_set_t* release() noexcept; + private: /** @brief Prepares stable read-only element references for iteration. */ @@ -400,15 +433,6 @@ class VkeyWitnessSet private: - /** @brief Allows sub-transactions to copy this value. */ - friend class SubTransaction; - - /** @brief Allows transactions to copy this value. */ - friend class Transaction; - - /** @brief Allows a witness set to copy this field. */ - friend class WitnessSet; - /** * @brief Adopts an owned collection. * @param value The owned collection. diff --git a/lib/include/Cometa/WitnessSet/WitnessSet.h b/lib/include/Cometa/WitnessSet/WitnessSet.h index 4c9ad471..fdfa2d7f 100644 --- a/lib/include/Cometa/WitnessSet/WitnessSet.h +++ b/lib/include/Cometa/WitnessSet/WitnessSet.h @@ -258,13 +258,38 @@ class WitnessSet */ bool operator!=(const WitnessSet& other) const; - private: + public: + + /** + * @brief Takes ownership of one native reference without copying it. + * @param value An owned reference; the caller must stop managing it after this call succeeds. + * @return The C++ owner of the supplied reference. + * @throws std::invalid_argument The reference is null; ownership is not transferred. + */ + static WitnessSet adopt(cardano_witness_set_t* value); + + /** + * @brief Borrows the native object for C interoperability. + * @return The native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + cardano_witness_set_t* nativeHandle() noexcept; - /** @brief Allows sub-transactions to copy this value. */ - friend class SubTransaction; + /** + * @brief Borrows the native object for read-only C interoperability. + * @return The read-only native pointer, or nullptr after a move or release. + * @remark Do not unref the borrowed pointer. Use it only until the next operation on this object. + */ + const cardano_witness_set_t* nativeHandle() const noexcept; - /** @brief Allows transactions to copy this value. */ - friend class Transaction; + /** + * @brief Transfers the owned native reference to the caller. + * @return The owned pointer, or nullptr if this object is already empty. + * @remark Leaves this object empty. The caller must adopt the reference or release it with the matching C unref function. + */ + cardano_witness_set_t* release() noexcept; + + private: /** * @brief Adopts an owned witness set. diff --git a/lib/src/Address/Address.cpp b/lib/src/Address/Address.cpp index 97ac1c21..a1e7422d 100644 --- a/lib/src/Address/Address.cpp +++ b/lib/src/Address/Address.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* INTERNAL IMPLEMENTATION ***************************************************/ namespace Cometa @@ -391,6 +393,35 @@ Address::operator!=(const Address& other) const return !(*this == other); } +Address +Address::adopt(cardano_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Address"); + } + + return Address(*value); +} + +cardano_address_t* +Address::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_address_t* +Address::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_address_t* +Address::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Address::Address(cardano_address_t& value) noexcept diff --git a/lib/src/Address/BaseAddress.cpp b/lib/src/Address/BaseAddress.cpp index 6810aafa..807b0010 100644 --- a/lib/src/Address/BaseAddress.cpp +++ b/lib/src/Address/BaseAddress.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -53,7 +55,7 @@ BaseAddress::BaseAddress(NetworkId network, const Credential& payment, const Cre const Credential stakeCopy(stake); cardano_base_address_t* value = nullptr; - const cardano_error_t result = cardano_base_address_from_credentials(static_cast(network), paymentCopy.checked(), stakeCopy.checked(), &value); + const cardano_error_t result = cardano_base_address_from_credentials(static_cast(network), checkedNativeHandle(paymentCopy), checkedNativeHandle(stakeCopy), &value); CardanoObject owner(value); @@ -100,7 +102,7 @@ BaseAddress BaseAddress::fromAddress(const Address& address) { cardano_base_address_t* value = nullptr; - const cardano_error_t result = cardano_base_address_from_address(address.checked(), &value); + const cardano_error_t result = cardano_base_address_from_address(checkedNativeHandle(address), &value); CardanoObject owner(value); @@ -152,7 +154,7 @@ BaseAddress::paymentCredential() const checkCardanoError(result, "BaseAddress paymentCredential"); - return Credential(owner.release()); + return Credential::adopt(owner.release()); } Credential @@ -166,7 +168,7 @@ BaseAddress::stakeCredential() const checkCardanoError(result, "BaseAddress stakeCredential"); - return Credential(owner.release()); + return Credential::adopt(owner.release()); } void @@ -214,6 +216,35 @@ BaseAddress::operator!=(const BaseAddress& other) const return !(*this == other); } +BaseAddress +BaseAddress::adopt(cardano_base_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null BaseAddress"); + } + + return BaseAddress(*value); +} + +cardano_base_address_t* +BaseAddress::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_base_address_t* +BaseAddress::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_base_address_t* +BaseAddress::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ BaseAddress::BaseAddress(cardano_base_address_t& value) noexcept diff --git a/lib/src/Address/ByronAddress.cpp b/lib/src/Address/ByronAddress.cpp index aa95f800..d9762fc3 100644 --- a/lib/src/Address/ByronAddress.cpp +++ b/lib/src/Address/ByronAddress.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -55,7 +57,7 @@ ByronAddress::ByronAddress(const Blake2bHash& root, const ByronAddressAttributes std::copy(attributes.derivationPath.begin(), attributes.derivationPath.end(), nativeAttributes.derivation_path); cardano_byron_address_t* value = nullptr; - const cardano_error_t result = cardano_byron_address_from_credentials(root.checked(), nativeAttributes, static_cast(type), &value); + const cardano_error_t result = cardano_byron_address_from_credentials(checkedNativeHandle(root), nativeAttributes, static_cast(type), &value); CardanoObject owner(value); @@ -102,7 +104,7 @@ ByronAddress ByronAddress::fromAddress(const Address& address) { cardano_byron_address_t* value = nullptr; - const cardano_error_t result = cardano_byron_address_from_address(address.checked(), &value); + const cardano_error_t result = cardano_byron_address_from_address(checkedNativeHandle(address), &value); CardanoObject owner(value); @@ -181,7 +183,7 @@ ByronAddress::root() const checkCardanoError(result, "ByronAddress root"); - return Blake2bHash(owner.release()); + return Blake2bHash::adopt(owner.release()); } void @@ -229,6 +231,35 @@ ByronAddress::operator!=(const ByronAddress& other) const return !(*this == other); } +ByronAddress +ByronAddress::adopt(cardano_byron_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ByronAddress"); + } + + return ByronAddress(*value); +} + +cardano_byron_address_t* +ByronAddress::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_byron_address_t* +ByronAddress::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_byron_address_t* +ByronAddress::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ByronAddress::ByronAddress(cardano_byron_address_t& value) noexcept diff --git a/lib/src/Address/EnterpriseAddress.cpp b/lib/src/Address/EnterpriseAddress.cpp index 7848d70c..bfa434cb 100644 --- a/lib/src/Address/EnterpriseAddress.cpp +++ b/lib/src/Address/EnterpriseAddress.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -52,7 +54,7 @@ EnterpriseAddress::EnterpriseAddress(NetworkId network, const Credential& paymen const Credential paymentCopy(payment); cardano_enterprise_address_t* value = nullptr; - const cardano_error_t result = cardano_enterprise_address_from_credentials(static_cast(network), paymentCopy.checked(), &value); + const cardano_error_t result = cardano_enterprise_address_from_credentials(static_cast(network), checkedNativeHandle(paymentCopy), &value); CardanoObject owner(value); @@ -99,7 +101,7 @@ EnterpriseAddress EnterpriseAddress::fromAddress(const Address& address) { cardano_enterprise_address_t* value = nullptr; - const cardano_error_t result = cardano_enterprise_address_from_address(address.checked(), &value); + const cardano_error_t result = cardano_enterprise_address_from_address(checkedNativeHandle(address), &value); CardanoObject owner(value); @@ -151,7 +153,7 @@ EnterpriseAddress::paymentCredential() const checkCardanoError(result, "EnterpriseAddress paymentCredential"); - return Credential(owner.release()); + return Credential::adopt(owner.release()); } void @@ -199,6 +201,35 @@ EnterpriseAddress::operator!=(const EnterpriseAddress& other) const return !(*this == other); } +EnterpriseAddress +EnterpriseAddress::adopt(cardano_enterprise_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null EnterpriseAddress"); + } + + return EnterpriseAddress(*value); +} + +cardano_enterprise_address_t* +EnterpriseAddress::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_enterprise_address_t* +EnterpriseAddress::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_enterprise_address_t* +EnterpriseAddress::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ EnterpriseAddress::EnterpriseAddress(cardano_enterprise_address_t& value) noexcept diff --git a/lib/src/Address/PointerAddress.cpp b/lib/src/Address/PointerAddress.cpp index 69445543..bc60028d 100644 --- a/lib/src/Address/PointerAddress.cpp +++ b/lib/src/Address/PointerAddress.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -59,7 +61,7 @@ PointerAddress::PointerAddress(NetworkId network, const Credential& payment, con const cardano_stake_pointer_t nativePointer { pointer.slot, pointer.transactionIndex, pointer.certificateIndex }; cardano_pointer_address_t* value = nullptr; - const cardano_error_t result = cardano_pointer_address_from_credentials(static_cast(network), paymentCopy.checked(), nativePointer, &value); + const cardano_error_t result = cardano_pointer_address_from_credentials(static_cast(network), checkedNativeHandle(paymentCopy), nativePointer, &value); CardanoObject owner(value); @@ -106,7 +108,7 @@ PointerAddress PointerAddress::fromAddress(const Address& address) { cardano_pointer_address_t* value = nullptr; - const cardano_error_t result = cardano_pointer_address_from_address(address.checked(), &value); + const cardano_error_t result = cardano_pointer_address_from_address(checkedNativeHandle(address), &value); CardanoObject owner(value); @@ -158,7 +160,7 @@ PointerAddress::paymentCredential() const checkCardanoError(result, "PointerAddress paymentCredential"); - return Credential(owner.release()); + return Credential::adopt(owner.release()); } StakePointer @@ -216,6 +218,35 @@ PointerAddress::operator!=(const PointerAddress& other) const return !(*this == other); } +PointerAddress +PointerAddress::adopt(cardano_pointer_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PointerAddress"); + } + + return PointerAddress(*value); +} + +cardano_pointer_address_t* +PointerAddress::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pointer_address_t* +PointerAddress::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pointer_address_t* +PointerAddress::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PointerAddress::PointerAddress(cardano_pointer_address_t& value) noexcept diff --git a/lib/src/Address/RewardAddress.cpp b/lib/src/Address/RewardAddress.cpp index 5592a1b0..8be51061 100644 --- a/lib/src/Address/RewardAddress.cpp +++ b/lib/src/Address/RewardAddress.cpp @@ -37,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -52,7 +54,7 @@ RewardAddress::RewardAddress(NetworkId network, const Credential& credential) const Credential credentialCopy(credential); cardano_reward_address_t* value = nullptr; - const cardano_error_t result = cardano_reward_address_from_credentials(static_cast(network), credentialCopy.checked(), &value); + const cardano_error_t result = cardano_reward_address_from_credentials(static_cast(network), checkedNativeHandle(credentialCopy), &value); CardanoObject owner(value); @@ -99,7 +101,7 @@ RewardAddress RewardAddress::fromAddress(const Address& address) { cardano_reward_address_t* value = nullptr; - const cardano_error_t result = cardano_reward_address_from_address(address.checked(), &value); + const cardano_error_t result = cardano_reward_address_from_address(checkedNativeHandle(address), &value); CardanoObject owner(value); @@ -151,7 +153,7 @@ RewardAddress::credential() const checkCardanoError(result, "RewardAddress credential"); - return Credential(owner.release()); + return Credential::adopt(owner.release()); } void @@ -199,6 +201,35 @@ RewardAddress::operator!=(const RewardAddress& other) const return !(*this == other); } +RewardAddress +RewardAddress::adopt(cardano_reward_address_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null RewardAddress"); + } + + return RewardAddress(*value); +} + +cardano_reward_address_t* +RewardAddress::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_reward_address_t* +RewardAddress::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_reward_address_t* +RewardAddress::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ RewardAddress::RewardAddress(cardano_reward_address_t& value) noexcept diff --git a/lib/src/Assets/AssetId.cpp b/lib/src/Assets/AssetId.cpp index ac7bd2b4..3966b9dc 100644 --- a/lib/src/Assets/AssetId.cpp +++ b/lib/src/Assets/AssetId.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,7 +44,7 @@ AssetId::AssetId(const Blake2bHash& policyId, const AssetName& assetName) const Blake2bHash policyCopy(policyId); const AssetName nameCopy(assetName); cardano_asset_id_t* value = nullptr; - const cardano_error_t result = cardano_asset_id_new(policyCopy.checked(), nameCopy.checked(), &value); + const cardano_error_t result = cardano_asset_id_new(checkedNativeHandle(policyCopy), checkedNativeHandle(nameCopy), &value); CardanoObject owner(value); @@ -113,7 +115,7 @@ AssetId::policyId() const return std::nullopt; } - const Blake2bHash policy(cardano_asset_id_get_policy_id(checked())); + const Blake2bHash policy = Blake2bHash::adopt(cardano_asset_id_get_policy_id(checked())); return policy; } @@ -126,7 +128,7 @@ AssetId::assetName() const return std::nullopt; } - const AssetName name(cardano_asset_id_get_asset_name(checked())); + const AssetName name = AssetName::adopt(cardano_asset_id_get_asset_name(checked())); return name; } @@ -199,6 +201,35 @@ AssetId::operator<(const AssetId& other) const return std::lexicographical_compare(left, left + cardano_asset_id_get_bytes_size(checked()), right, right + cardano_asset_id_get_bytes_size(other.checked())); } +AssetId +AssetId::adopt(cardano_asset_id_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AssetId"); + } + + return AssetId(value); +} + +cardano_asset_id_t* +AssetId::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_asset_id_t* +AssetId::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_asset_id_t* +AssetId::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AssetId::AssetId(cardano_asset_id_t* value) noexcept diff --git a/lib/src/Assets/AssetIdMap.cpp b/lib/src/Assets/AssetIdMap.cpp index a8aa8e78..7a7b1f04 100644 --- a/lib/src/Assets/AssetIdMap.cpp +++ b/lib/src/Assets/AssetIdMap.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -100,7 +102,7 @@ std::optional AssetIdMap::get(const AssetId& key) const { std::int64_t amount = 0; - const cardano_error_t result = cardano_asset_id_map_get(checked(), key.checked(), &amount); + const cardano_error_t result = cardano_asset_id_map_get(checked(), checkedNativeHandle(key), &amount); if (result == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -116,7 +118,7 @@ AssetIdMap::set(const AssetId& key, std::int64_t amount) { const AssetId copy(key); - checkCardanoError(cardano_asset_id_map_insert(checked(), copy.checked(), amount), "AssetIdMap set"); + checkCardanoError(cardano_asset_id_map_insert(checked(), checkedNativeHandle(copy), amount), "AssetIdMap set"); invalidateElements(); } @@ -134,7 +136,7 @@ AssetIdMap::keys() const CardanoObject owner(key); checkCardanoError(status, "AssetIdMap keys"); - const AssetId value(owner.release()); + const AssetId value = AssetId::adopt(owner.release()); result.push_back(value); } @@ -156,7 +158,7 @@ AssetIdMap::entries() const CardanoObject owner(key); checkCardanoError(status, "AssetIdMap entries"); - const AssetId value(owner.release()); + const AssetId value = AssetId::adopt(owner.release()); result.emplace_back(value, amount); } @@ -496,6 +498,60 @@ AssetIdMap::clear() m_mutableAccess = true; } +AssetIdMap +AssetIdMap::adopt(cardano_asset_id_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AssetIdMap"); + } + + return AssetIdMap(value); +} + +cardano_asset_id_map_t* +AssetIdMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_asset_id_map_t* +AssetIdMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_asset_id_map_t* +AssetIdMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AssetIdMap::AssetIdMap(cardano_asset_id_map_t* value) noexcept diff --git a/lib/src/Assets/AssetName.cpp b/lib/src/Assets/AssetName.cpp index 14aa80b0..e2f96216 100644 --- a/lib/src/Assets/AssetName.cpp +++ b/lib/src/Assets/AssetName.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -193,6 +195,35 @@ AssetName::operator<(const AssetName& other) const return toBytes() < other.toBytes(); } +AssetName +AssetName::adopt(cardano_asset_name_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AssetName"); + } + + return AssetName(value); +} + +cardano_asset_name_t* +AssetName::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_asset_name_t* +AssetName::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_asset_name_t* +AssetName::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AssetName::AssetName(cardano_asset_name_t* value) noexcept diff --git a/lib/src/Assets/AssetNameMap.cpp b/lib/src/Assets/AssetNameMap.cpp index c1c3713b..0fc5e1d0 100644 --- a/lib/src/Assets/AssetNameMap.cpp +++ b/lib/src/Assets/AssetNameMap.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -123,7 +125,7 @@ std::optional AssetNameMap::get(const AssetName& key) const { std::int64_t amount = 0; - const cardano_error_t result = cardano_asset_name_map_get(checked(), key.checked(), &amount); + const cardano_error_t result = cardano_asset_name_map_get(checked(), checkedNativeHandle(key), &amount); if (result == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -139,7 +141,7 @@ AssetNameMap::set(const AssetName& key, std::int64_t amount) { const AssetName copy(key); - checkCardanoError(cardano_asset_name_map_insert(checked(), copy.checked(), amount), "AssetNameMap set"); + checkCardanoError(cardano_asset_name_map_insert(checked(), checkedNativeHandle(copy), amount), "AssetNameMap set"); invalidateElements(); } @@ -157,7 +159,7 @@ AssetNameMap::keys() const CardanoObject owner(key); checkCardanoError(status, "AssetNameMap keys"); - const AssetName value(owner.release()); + const AssetName value = AssetName::adopt(owner.release()); result.push_back(value); } @@ -179,7 +181,7 @@ AssetNameMap::entries() const CardanoObject owner(key); checkCardanoError(status, "AssetNameMap entries"); - const AssetName value(owner.release()); + const AssetName value = AssetName::adopt(owner.release()); result.emplace_back(value, amount); } @@ -537,6 +539,60 @@ AssetNameMap::clear() m_mutableAccess = true; } +AssetNameMap +AssetNameMap::adopt(cardano_asset_name_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AssetNameMap"); + } + + return AssetNameMap(value); +} + +cardano_asset_name_map_t* +AssetNameMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_asset_name_map_t* +AssetNameMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_asset_name_map_t* +AssetNameMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AssetNameMap::AssetNameMap(cardano_asset_name_map_t* value) noexcept diff --git a/lib/src/Assets/MultiAsset.cpp b/lib/src/Assets/MultiAsset.cpp index d0f80cee..4c877275 100644 --- a/lib/src/Assets/MultiAsset.cpp +++ b/lib/src/Assets/MultiAsset.cpp @@ -53,6 +53,8 @@ validatePolicy(const Cometa::Blake2bHash& policyId) } } // namespace +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -147,7 +149,7 @@ MultiAsset::assets(const Blake2bHash& policyId) const validatePolicy(policyId); cardano_asset_name_map_t* value = nullptr; - const cardano_error_t result = cardano_multi_asset_get_assets(checked(), policyId.checked(), &value); + const cardano_error_t result = cardano_multi_asset_get_assets(checked(), checkedNativeHandle(policyId), &value); CardanoObject owner(value); if (result == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -156,7 +158,7 @@ MultiAsset::assets(const Blake2bHash& policyId) const } checkCardanoError(result, "MultiAsset assets"); - const AssetNameMap map(owner.release()); + const AssetNameMap map = AssetNameMap::adopt(owner.release()); return map; } @@ -169,7 +171,7 @@ MultiAsset::setAssets(const Blake2bHash& policyId, const AssetNameMap& assets) const Blake2bHash policyCopy(policyId); const AssetNameMap assetsCopy(assets); - checkCardanoError(cardano_multi_asset_insert_assets(checked(), policyCopy.checked(), assetsCopy.checked()), "MultiAsset setAssets"); + checkCardanoError(cardano_multi_asset_insert_assets(checked(), checkedNativeHandle(policyCopy), checkedNativeHandle(assetsCopy)), "MultiAsset setAssets"); invalidateElements(); } @@ -179,7 +181,7 @@ MultiAsset::get(const Blake2bHash& policyId, const AssetName& name) const validatePolicy(policyId); std::int64_t amount = 0; - const cardano_error_t result = cardano_multi_asset_get(checked(), policyId.checked(), name.checked(), &amount); + const cardano_error_t result = cardano_multi_asset_get(checked(), checkedNativeHandle(policyId), checkedNativeHandle(name), &amount); if (result == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -210,7 +212,7 @@ MultiAsset::set(const Blake2bHash& policyId, const AssetName& name, std::int64_t const Blake2bHash policyCopy(policyId); const AssetName nameCopy(name); - checkCardanoError(cardano_multi_asset_set(copy.checked(), policyCopy.checked(), nameCopy.checked(), amount), "MultiAsset set"); + checkCardanoError(cardano_multi_asset_set(copy.nativeHandle(), checkedNativeHandle(policyCopy), checkedNativeHandle(nameCopy), amount), "MultiAsset set"); swap(copy); invalidateElements(); } @@ -246,7 +248,7 @@ MultiAsset::policies() const CardanoObject hashOwner(hash); checkCardanoError(getResult, "MultiAsset policy"); - const Blake2bHash policy(hashOwner.release()); + const Blake2bHash policy = Blake2bHash::adopt(hashOwner.release()); result.push_back(policy); } @@ -688,6 +690,60 @@ MultiAsset::empty() const return size() == 0; } +MultiAsset +MultiAsset::adopt(cardano_multi_asset_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MultiAsset"); + } + + return MultiAsset(value); +} + +cardano_multi_asset_t* +MultiAsset::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_multi_asset_t* +MultiAsset::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_multi_asset_t* +MultiAsset::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MultiAsset::MultiAsset(cardano_multi_asset_t* value) noexcept diff --git a/lib/src/AuxiliaryData/AuxiliaryData.cpp b/lib/src/AuxiliaryData/AuxiliaryData.cpp index c412b0e6..3e59f7d3 100644 --- a/lib/src/AuxiliaryData/AuxiliaryData.cpp +++ b/lib/src/AuxiliaryData/AuxiliaryData.cpp @@ -26,6 +26,7 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include #include @@ -35,6 +36,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -80,7 +83,7 @@ AuxiliaryData::fromCbor(const std::vector& cbor) { AuxiliaryData value(*decodeCbor(cbor, cardano_auxiliary_data_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -102,7 +105,7 @@ AuxiliaryData::metadata() const return std::nullopt; } - const TransactionMetadata data(*owner.release()); + const TransactionMetadata data = TransactionMetadata::adopt(owner.release()); return TransactionMetadata(data); } @@ -119,7 +122,7 @@ AuxiliaryData::setMetadata(const std::optional& value) TransactionMetadata copy(*value); - checkCardanoError(cardano_auxiliary_data_set_transaction_metadata(checked(), copy.checked()), "AuxiliaryData setMetadata"); + checkCardanoError(cardano_auxiliary_data_set_transaction_metadata(checked(), checkedNativeHandle(copy)), "AuxiliaryData setMetadata"); normalizeEncoding(); } @@ -134,7 +137,7 @@ AuxiliaryData::nativeScripts() const return std::nullopt; } - const NativeScriptList data(*owner.release()); + const NativeScriptList data = NativeScriptList::adopt(owner.release()); return NativeScriptList(data); } @@ -151,7 +154,7 @@ AuxiliaryData::setNativeScripts(const std::optional& value) NativeScriptList copy(*value); - checkCardanoError(cardano_auxiliary_data_set_native_scripts(checked(), copy.checked()), "AuxiliaryData setNativeScripts"); + checkCardanoError(cardano_auxiliary_data_set_native_scripts(checked(), checkedNativeHandle(copy)), "AuxiliaryData setNativeScripts"); normalizeEncoding(); } @@ -166,7 +169,7 @@ AuxiliaryData::plutusV1Scripts() const return std::nullopt; } - const PlutusV1ScriptList data(*owner.release()); + const PlutusV1ScriptList data = PlutusV1ScriptList::adopt(owner.release()); return PlutusV1ScriptList(data); } @@ -183,7 +186,7 @@ AuxiliaryData::setPlutusV1Scripts(const std::optional& value PlutusV1ScriptList copy(*value); - checkCardanoError(cardano_auxiliary_data_set_plutus_v1_scripts(checked(), copy.checked()), "AuxiliaryData setPlutusV1Scripts"); + checkCardanoError(cardano_auxiliary_data_set_plutus_v1_scripts(checked(), checkedNativeHandle(copy)), "AuxiliaryData setPlutusV1Scripts"); normalizeEncoding(); } @@ -198,7 +201,7 @@ AuxiliaryData::plutusV2Scripts() const return std::nullopt; } - const PlutusV2ScriptList data(*owner.release()); + const PlutusV2ScriptList data = PlutusV2ScriptList::adopt(owner.release()); return PlutusV2ScriptList(data); } @@ -215,7 +218,7 @@ AuxiliaryData::setPlutusV2Scripts(const std::optional& value PlutusV2ScriptList copy(*value); - checkCardanoError(cardano_auxiliary_data_set_plutus_v2_scripts(checked(), copy.checked()), "AuxiliaryData setPlutusV2Scripts"); + checkCardanoError(cardano_auxiliary_data_set_plutus_v2_scripts(checked(), checkedNativeHandle(copy)), "AuxiliaryData setPlutusV2Scripts"); normalizeEncoding(); } @@ -230,7 +233,7 @@ AuxiliaryData::plutusV3Scripts() const return std::nullopt; } - const PlutusV3ScriptList data(*owner.release()); + const PlutusV3ScriptList data = PlutusV3ScriptList::adopt(owner.release()); return PlutusV3ScriptList(data); } @@ -247,7 +250,7 @@ AuxiliaryData::setPlutusV3Scripts(const std::optional& value PlutusV3ScriptList copy(*value); - checkCardanoError(cardano_auxiliary_data_set_plutus_v3_scripts(checked(), copy.checked()), "AuxiliaryData setPlutusV3Scripts"); + checkCardanoError(cardano_auxiliary_data_set_plutus_v3_scripts(checked(), checkedNativeHandle(copy)), "AuxiliaryData setPlutusV3Scripts"); normalizeEncoding(); } @@ -262,7 +265,7 @@ AuxiliaryData::plutusV4Scripts() const return std::nullopt; } - const PlutusV4ScriptList data(*owner.release()); + const PlutusV4ScriptList data = PlutusV4ScriptList::adopt(owner.release()); return PlutusV4ScriptList(data); } @@ -279,7 +282,7 @@ AuxiliaryData::setPlutusV4Scripts(const std::optional& value PlutusV4ScriptList copy(*value); - checkCardanoError(cardano_auxiliary_data_set_plutus_v4_scripts(checked(), copy.checked()), "AuxiliaryData setPlutusV4Scripts"); + checkCardanoError(cardano_auxiliary_data_set_plutus_v4_scripts(checked(), checkedNativeHandle(copy)), "AuxiliaryData setPlutusV4Scripts"); normalizeEncoding(); } @@ -355,6 +358,35 @@ AuxiliaryData::operator!=(const AuxiliaryData& other) const return !(*this == other); } +AuxiliaryData +AuxiliaryData::adopt(cardano_auxiliary_data_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AuxiliaryData"); + } + + return AuxiliaryData(*value); +} + +cardano_auxiliary_data_t* +AuxiliaryData::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_auxiliary_data_t* +AuxiliaryData::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_auxiliary_data_t* +AuxiliaryData::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AuxiliaryData::AuxiliaryData(cardano_auxiliary_data_t& value) noexcept @@ -374,19 +406,19 @@ AuxiliaryData::checked() const } void -AuxiliaryData::validate() const +validateValue(const AuxiliaryData& value) { - const std::optional metadataValue = metadata(); - const std::optional scripts = nativeScripts(); + const std::optional metadataValue = value.metadata(); + const std::optional scripts = value.nativeScripts(); if (metadataValue) { - metadataValue->validate(); + validateValue(*metadataValue); } if (scripts) { - scripts->validate(); + validateValue(*scripts); } } diff --git a/lib/src/AuxiliaryData/Metadatum.cpp b/lib/src/AuxiliaryData/Metadatum.cpp index 63d765e0..96852a48 100644 --- a/lib/src/AuxiliaryData/Metadatum.cpp +++ b/lib/src/AuxiliaryData/Metadatum.cpp @@ -58,7 +58,7 @@ Metadatum::Metadatum(const BigInt& integer) : m_value(nullptr) { cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_new_integer(integer.checked(), &value); + const cardano_error_t result = cardano_metadatum_new_integer(checkedNativeHandle(integer), &value); CardanoObject owner(value); @@ -86,7 +86,7 @@ Metadatum::Metadatum(const MetadatumList& data) MetadatumList copy(data); cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_new_list(copy.checked(), &value); + const cardano_error_t result = cardano_metadatum_new_list(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -99,7 +99,7 @@ Metadatum::Metadatum(MetadatumList&& data) : m_value(nullptr) { cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_new_list(data.checked(), &value); + const cardano_error_t result = cardano_metadatum_new_list(checkedNativeHandle(data), &value); CardanoObject owner(value); @@ -116,7 +116,7 @@ Metadatum::Metadatum(const MetadatumMap& data) MetadatumMap copy(data); cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_new_map(copy.checked(), &value); + const cardano_error_t result = cardano_metadatum_new_map(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -129,7 +129,7 @@ Metadatum::Metadatum(MetadatumMap&& data) : m_value(nullptr) { cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_new_map(data.checked(), &value); + const cardano_error_t result = cardano_metadatum_new_map(checkedNativeHandle(data), &value); CardanoObject owner(value); @@ -233,7 +233,7 @@ Metadatum::asList() const checkCardanoError(result, "Metadatum asList"); - const MetadatumList data(*owner.release()); + const MetadatumList data = MetadatumList::adopt(owner.release()); return MetadatumList(data); } @@ -248,7 +248,7 @@ Metadatum::asMap() const checkCardanoError(result, "Metadatum asMap"); - const MetadatumMap data(*owner.release()); + const MetadatumMap data = MetadatumMap::adopt(owner.release()); return MetadatumMap(data); } @@ -279,7 +279,7 @@ Metadatum::asInteger() const checkCardanoError(result, "Metadatum asInteger"); - return BigInt(*owner.release()); + return BigInt::adopt(owner.release()); } std::vector @@ -368,6 +368,35 @@ Metadatum::operator!=(const Metadatum& other) const return !(*this == other); } +Metadatum +Metadatum::adopt(cardano_metadatum_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Metadatum"); + } + + return Metadatum(*value); +} + +cardano_metadatum_t* +Metadatum::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_metadatum_t* +Metadatum::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_metadatum_t* +Metadatum::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Metadatum::Metadatum(cardano_metadatum_t& value) noexcept diff --git a/lib/src/AuxiliaryData/MetadatumList.cpp b/lib/src/AuxiliaryData/MetadatumList.cpp index 42ae0a9d..da813bc8 100644 --- a/lib/src/AuxiliaryData/MetadatumList.cpp +++ b/lib/src/AuxiliaryData/MetadatumList.cpp @@ -34,6 +34,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -127,7 +129,7 @@ MetadatumList::pushBack(const Metadatum& data) Metadatum copy(data); - checkCardanoError(cardano_metadatum_list_add(checked(), copy.checked()), "MetadatumList pushBack"); + checkCardanoError(cardano_metadatum_list_add(checked(), checkedNativeHandle(copy)), "MetadatumList pushBack"); } std::vector @@ -467,6 +469,60 @@ MetadatumList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +MetadatumList +MetadatumList::adopt(cardano_metadatum_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MetadatumList"); + } + + return MetadatumList(*value); +} + +cardano_metadatum_list_t* +MetadatumList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_metadatum_list_t* +MetadatumList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_metadatum_list_t* +MetadatumList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MetadatumList::MetadatumList(cardano_metadatum_list_t& value) noexcept @@ -560,7 +616,7 @@ MetadatumList::copyElement(std::size_t index) const checkCardanoError(result, "MetadatumList at"); - const Metadatum data(*owner.release()); + const Metadatum data = Metadatum::adopt(owner.release()); return Metadatum(data); } diff --git a/lib/src/AuxiliaryData/MetadatumMap.cpp b/lib/src/AuxiliaryData/MetadatumMap.cpp index a646511d..636fd8fe 100644 --- a/lib/src/AuxiliaryData/MetadatumMap.cpp +++ b/lib/src/AuxiliaryData/MetadatumMap.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -109,7 +111,7 @@ std::optional MetadatumMap::get(const Metadatum& key) const { cardano_metadatum_t* value = nullptr; - const cardano_error_t result = cardano_metadatum_map_get(checked(), key.checked(), &value); + const cardano_error_t result = cardano_metadatum_map_get(checked(), checkedNativeHandle(key), &value); CardanoObject owner(value); @@ -120,7 +122,7 @@ MetadatumMap::get(const Metadatum& key) const checkCardanoError(result, "MetadatumMap get"); - const Metadatum data(*owner.release()); + const Metadatum data = Metadatum::adopt(owner.release()); return Metadatum(data); } @@ -137,7 +139,7 @@ MetadatumMap::insert(const Metadatum& key, const Metadatum& value) Metadatum keyCopy(key); Metadatum valueCopy(value); - checkCardanoError(cardano_metadatum_map_insert(checked(), keyCopy.checked(), valueCopy.checked()), "MetadatumMap insert"); + checkCardanoError(cardano_metadatum_map_insert(checked(), checkedNativeHandle(keyCopy), checkedNativeHandle(valueCopy)), "MetadatumMap insert"); } std::vector @@ -150,7 +152,7 @@ MetadatumMap::keys() const checkCardanoError(result, "MetadatumMap keys"); - const MetadatumList list(*owner.release()); + const MetadatumList list = MetadatumList::adopt(owner.release()); return list.values(); } @@ -165,7 +167,7 @@ MetadatumMap::values() const checkCardanoError(result, "MetadatumMap values"); - const MetadatumList list(*owner.release()); + const MetadatumList list = MetadatumList::adopt(owner.release()); return list.values(); } @@ -204,8 +206,8 @@ MetadatumMap::entryAt(std::size_t index) const checkCardanoError(result, "MetadatumMap entryAt"); - const Metadatum keyValue(*keyOwner.release()); - const Metadatum dataValue(*valueOwner.release()); + const Metadatum keyValue = Metadatum::adopt(keyOwner.release()); + const Metadatum dataValue = Metadatum::adopt(valueOwner.release()); return std::make_pair(Metadatum(keyValue), Metadatum(dataValue)); } @@ -543,6 +545,60 @@ MetadatumMap::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +MetadatumMap +MetadatumMap::adopt(cardano_metadatum_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MetadatumMap"); + } + + return MetadatumMap(*value); +} + +cardano_metadatum_map_t* +MetadatumMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_metadatum_map_t* +MetadatumMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_metadatum_map_t* +MetadatumMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MetadatumMap::MetadatumMap(cardano_metadatum_map_t& value) noexcept diff --git a/lib/src/AuxiliaryData/PlutusV1ScriptList.cpp b/lib/src/AuxiliaryData/PlutusV1ScriptList.cpp index 74d9756e..40aa7c78 100644 --- a/lib/src/AuxiliaryData/PlutusV1ScriptList.cpp +++ b/lib/src/AuxiliaryData/PlutusV1ScriptList.cpp @@ -35,6 +35,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -130,7 +132,7 @@ PlutusV1ScriptList::pushBack(const PlutusV1Script& script) PlutusV1Script copy(script); - checkCardanoError(cardano_plutus_v1_script_list_add(checked(), copy.checked()), "PlutusV1ScriptList pushBack"); + checkCardanoError(cardano_plutus_v1_script_list_add(checked(), checkedNativeHandle(copy)), "PlutusV1ScriptList pushBack"); } std::vector @@ -470,6 +472,60 @@ PlutusV1ScriptList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusV1ScriptList +PlutusV1ScriptList::adopt(cardano_plutus_v1_script_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV1ScriptList"); + } + + return PlutusV1ScriptList(*value); +} + +cardano_plutus_v1_script_list_t* +PlutusV1ScriptList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_v1_script_list_t* +PlutusV1ScriptList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_v1_script_list_t* +PlutusV1ScriptList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV1ScriptList::PlutusV1ScriptList(cardano_plutus_v1_script_list_t& value) noexcept @@ -563,7 +619,7 @@ PlutusV1ScriptList::copyElement(std::size_t index) const checkCardanoError(result, "PlutusV1ScriptList at"); - const PlutusV1Script script(*owner.release()); + const PlutusV1Script script = PlutusV1Script::adopt(owner.release()); return PlutusV1Script(script); } diff --git a/lib/src/AuxiliaryData/PlutusV2ScriptList.cpp b/lib/src/AuxiliaryData/PlutusV2ScriptList.cpp index b52f42d5..25978902 100644 --- a/lib/src/AuxiliaryData/PlutusV2ScriptList.cpp +++ b/lib/src/AuxiliaryData/PlutusV2ScriptList.cpp @@ -35,6 +35,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -130,7 +132,7 @@ PlutusV2ScriptList::pushBack(const PlutusV2Script& script) PlutusV2Script copy(script); - checkCardanoError(cardano_plutus_v2_script_list_add(checked(), copy.checked()), "PlutusV2ScriptList pushBack"); + checkCardanoError(cardano_plutus_v2_script_list_add(checked(), checkedNativeHandle(copy)), "PlutusV2ScriptList pushBack"); } std::vector @@ -470,6 +472,60 @@ PlutusV2ScriptList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusV2ScriptList +PlutusV2ScriptList::adopt(cardano_plutus_v2_script_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV2ScriptList"); + } + + return PlutusV2ScriptList(*value); +} + +cardano_plutus_v2_script_list_t* +PlutusV2ScriptList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_v2_script_list_t* +PlutusV2ScriptList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_v2_script_list_t* +PlutusV2ScriptList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV2ScriptList::PlutusV2ScriptList(cardano_plutus_v2_script_list_t& value) noexcept @@ -563,7 +619,7 @@ PlutusV2ScriptList::copyElement(std::size_t index) const checkCardanoError(result, "PlutusV2ScriptList at"); - const PlutusV2Script script(*owner.release()); + const PlutusV2Script script = PlutusV2Script::adopt(owner.release()); return PlutusV2Script(script); } diff --git a/lib/src/AuxiliaryData/PlutusV3ScriptList.cpp b/lib/src/AuxiliaryData/PlutusV3ScriptList.cpp index 1349cb50..f50d8ec2 100644 --- a/lib/src/AuxiliaryData/PlutusV3ScriptList.cpp +++ b/lib/src/AuxiliaryData/PlutusV3ScriptList.cpp @@ -35,6 +35,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -130,7 +132,7 @@ PlutusV3ScriptList::pushBack(const PlutusV3Script& script) PlutusV3Script copy(script); - checkCardanoError(cardano_plutus_v3_script_list_add(checked(), copy.checked()), "PlutusV3ScriptList pushBack"); + checkCardanoError(cardano_plutus_v3_script_list_add(checked(), checkedNativeHandle(copy)), "PlutusV3ScriptList pushBack"); } std::vector @@ -470,6 +472,60 @@ PlutusV3ScriptList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusV3ScriptList +PlutusV3ScriptList::adopt(cardano_plutus_v3_script_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV3ScriptList"); + } + + return PlutusV3ScriptList(*value); +} + +cardano_plutus_v3_script_list_t* +PlutusV3ScriptList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_v3_script_list_t* +PlutusV3ScriptList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_v3_script_list_t* +PlutusV3ScriptList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV3ScriptList::PlutusV3ScriptList(cardano_plutus_v3_script_list_t& value) noexcept @@ -563,7 +619,7 @@ PlutusV3ScriptList::copyElement(std::size_t index) const checkCardanoError(result, "PlutusV3ScriptList at"); - const PlutusV3Script script(*owner.release()); + const PlutusV3Script script = PlutusV3Script::adopt(owner.release()); return PlutusV3Script(script); } diff --git a/lib/src/AuxiliaryData/PlutusV4ScriptList.cpp b/lib/src/AuxiliaryData/PlutusV4ScriptList.cpp index ef0e357e..da5e31ec 100644 --- a/lib/src/AuxiliaryData/PlutusV4ScriptList.cpp +++ b/lib/src/AuxiliaryData/PlutusV4ScriptList.cpp @@ -35,6 +35,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -130,7 +132,7 @@ PlutusV4ScriptList::pushBack(const PlutusV4Script& script) PlutusV4Script copy(script); - checkCardanoError(cardano_plutus_v4_script_list_add(checked(), copy.checked()), "PlutusV4ScriptList pushBack"); + checkCardanoError(cardano_plutus_v4_script_list_add(checked(), checkedNativeHandle(copy)), "PlutusV4ScriptList pushBack"); } std::vector @@ -470,6 +472,60 @@ PlutusV4ScriptList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusV4ScriptList +PlutusV4ScriptList::adopt(cardano_plutus_v4_script_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV4ScriptList"); + } + + return PlutusV4ScriptList(*value); +} + +cardano_plutus_v4_script_list_t* +PlutusV4ScriptList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_v4_script_list_t* +PlutusV4ScriptList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_v4_script_list_t* +PlutusV4ScriptList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV4ScriptList::PlutusV4ScriptList(cardano_plutus_v4_script_list_t& value) noexcept @@ -563,7 +619,7 @@ PlutusV4ScriptList::copyElement(std::size_t index) const checkCardanoError(result, "PlutusV4ScriptList at"); - const PlutusV4Script script(*owner.release()); + const PlutusV4Script script = PlutusV4Script::adopt(owner.release()); return PlutusV4Script(script); } diff --git a/lib/src/AuxiliaryData/TransactionMetadata.cpp b/lib/src/AuxiliaryData/TransactionMetadata.cpp index 2fe41599..45aa32e4 100644 --- a/lib/src/AuxiliaryData/TransactionMetadata.cpp +++ b/lib/src/AuxiliaryData/TransactionMetadata.cpp @@ -26,10 +26,13 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -79,7 +82,7 @@ TransactionMetadata::fromCbor(const std::vector& cbor) { TransactionMetadata value(*decodeCbor(cbor, cardano_transaction_metadata_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -122,7 +125,7 @@ TransactionMetadata::get(std::uint64_t label) const checkCardanoError(result, "TransactionMetadata get"); - const Metadatum data(*owner.release()); + const Metadatum data = Metadatum::adopt(owner.release()); return Metadatum(data); } @@ -140,14 +143,14 @@ TransactionMetadata::set(std::uint64_t label, const Metadatum& value) for (const std::pair& entry: current) { const Metadatum& item = entry.first == label ? copy : entry.second; - checkCardanoError(cardano_transaction_metadata_insert(replacement.checked(), entry.first, item.checked()), "TransactionMetadata replacement"); + checkCardanoError(cardano_transaction_metadata_insert(replacement.checked(), entry.first, checkedNativeHandle(item)), "TransactionMetadata replacement"); } swap(replacement); return; } - checkCardanoError(cardano_transaction_metadata_insert(checked(), label, copy.checked()), "TransactionMetadata set"); + checkCardanoError(cardano_transaction_metadata_insert(checked(), label, checkedNativeHandle(copy)), "TransactionMetadata set"); invalidateElements(); } @@ -167,7 +170,7 @@ TransactionMetadata::entryAt(std::size_t index) const checkCardanoError(result, "TransactionMetadata entryAt"); - const Metadatum data(*owner.release()); + const Metadatum data = Metadatum::adopt(owner.release()); return std::make_pair(label, Metadatum(data)); } @@ -503,6 +506,60 @@ TransactionMetadata::clear() m_mutableAccess = true; } +TransactionMetadata +TransactionMetadata::adopt(cardano_transaction_metadata_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null TransactionMetadata"); + } + + return TransactionMetadata(*value); +} + +cardano_transaction_metadata_t* +TransactionMetadata::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_transaction_metadata_t* +TransactionMetadata::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_transaction_metadata_t* +TransactionMetadata::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ TransactionMetadata::TransactionMetadata(cardano_transaction_metadata_t& value) noexcept @@ -524,9 +581,9 @@ TransactionMetadata::checked() const } void -TransactionMetadata::validate() const +validateValue(const TransactionMetadata& value) { - const MetadatumLabelList labels = keys(); + const MetadatumLabelList labels = value.keys(); for (std::size_t index = 1U; index < labels.size(); ++index) { diff --git a/lib/src/CardanoInterop.h b/lib/src/CardanoInterop.h index 3cc30caa..8f980100 100644 --- a/lib/src/CardanoInterop.h +++ b/lib/src/CardanoInterop.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -66,6 +67,27 @@ checkCardanoError(cardano_error_t error, const char* operation) } } +/** + * @brief Borrows a live native object for an internal C call. + * @tparam T The C++ wrapper type. + * @param value The wrapper to borrow without invalidating C++ element references. + * @return The borrowed pointer; C APIs may update reference counts but must not change the value. + * @throws std::logic_error The wrapper is empty. + */ +template +std::remove_const_t().nativeHandle())>>* +checkedNativeHandle(const T& value) +{ + const decltype(value.nativeHandle()) handle = value.nativeHandle(); + + if (!handle) + { + throw std::logic_error("Cannot observe an empty value"); + } + + return const_cast>*>(handle); +} + /** * @brief Releases one owned native reference using its typed unref function. */ diff --git a/lib/src/Cbor/CborReader.cpp b/lib/src/Cbor/CborReader.cpp index 2a508a58..1da48225 100644 --- a/lib/src/Cbor/CborReader.cpp +++ b/lib/src/Cbor/CborReader.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -317,7 +319,7 @@ CborReader::readBigInt() checkCardanoError(result, "CborReader readBigInt"); - return BigInt(*owner.release()); + return BigInt::adopt(owner.release()); } CborTag @@ -379,8 +381,42 @@ CborReader::operator=(CborReader&& other) noexcept return *this; } +CborReader +CborReader::adopt(cardano_cbor_reader_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CborReader"); + } + + return CborReader(value); +} + +cardano_cbor_reader_t* +CborReader::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_cbor_reader_t* +CborReader::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_cbor_reader_t* +CborReader::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ +CborReader::CborReader(cardano_cbor_reader_t* value) noexcept +: m_value(value) +{ +} + cardano_cbor_reader_t* CborReader::checked() const { diff --git a/lib/src/Cbor/CborWriter.cpp b/lib/src/Cbor/CborWriter.cpp index e789c5bb..3812527a 100644 --- a/lib/src/Cbor/CborWriter.cpp +++ b/lib/src/Cbor/CborWriter.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -164,7 +166,7 @@ CborWriter::writeText(std::string_view text) void CborWriter::writeBigInt(const BigInt& value) { - checkCardanoError(cardano_cbor_writer_write_bigint(checked(), value.checked()), "CborWriter writeBigInt"); + checkCardanoError(cardano_cbor_writer_write_bigint(checked(), checkedNativeHandle(value)), "CborWriter writeBigInt"); } void @@ -240,8 +242,42 @@ CborWriter::operator=(CborWriter&& other) noexcept return *this; } +CborWriter +CborWriter::adopt(cardano_cbor_writer_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CborWriter"); + } + + return CborWriter(value); +} + +cardano_cbor_writer_t* +CborWriter::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_cbor_writer_t* +CborWriter::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_cbor_writer_t* +CborWriter::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ +CborWriter::CborWriter(cardano_cbor_writer_t* value) noexcept +: m_value(value) +{ +} + cardano_cbor_writer_t* CborWriter::checked() const { diff --git a/lib/src/Certificates/AuthCommitteeHotCert.cpp b/lib/src/Certificates/AuthCommitteeHotCert.cpp index 109bbd79..03326cae 100644 --- a/lib/src/Certificates/AuthCommitteeHotCert.cpp +++ b/lib/src/Certificates/AuthCommitteeHotCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ AuthCommitteeHotCert::AuthCommitteeHotCert(const Credential& coldCredential, con const Credential coldCopy(coldCredential); const Credential hotCopy(hotCredential); cardano_auth_committee_hot_cert_t* value = nullptr; - const cardano_error_t status = cardano_auth_committee_hot_cert_new(coldCopy.checked(), hotCopy.checked(), &value); + const cardano_error_t status = cardano_auth_committee_hot_cert_new(checkedNativeHandle(coldCopy), checkedNativeHandle(hotCopy), &value); CardanoObject owner(value); checkCardanoError(status, "AuthCommitteeHotCert"); @@ -89,7 +91,7 @@ AuthCommitteeHotCert::coldCredential() const CardanoObject owner(value); checkCardanoError(status, "AuthCommitteeHotCert coldCredential"); - const Credential result(owner.release()); + const Credential result = Credential::adopt(owner.release()); return Credential(result); } @@ -97,7 +99,7 @@ void AuthCommitteeHotCert::setColdCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_auth_committee_hot_cert_set_cold_cred(checked(), copy.checked()), "AuthCommitteeHotCert setColdCredential"); + checkCardanoError(cardano_auth_committee_hot_cert_set_cold_cred(checked(), checkedNativeHandle(copy)), "AuthCommitteeHotCert setColdCredential"); } Credential @@ -108,7 +110,7 @@ AuthCommitteeHotCert::hotCredential() const CardanoObject owner(value); checkCardanoError(status, "AuthCommitteeHotCert hotCredential"); - const Credential result(owner.release()); + const Credential result = Credential::adopt(owner.release()); return Credential(result); } @@ -116,7 +118,7 @@ void AuthCommitteeHotCert::setHotCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_auth_committee_hot_cert_set_hot_cred(checked(), copy.checked()), "AuthCommitteeHotCert setHotCredential"); + checkCardanoError(cardano_auth_committee_hot_cert_set_hot_cred(checked(), checkedNativeHandle(copy)), "AuthCommitteeHotCert setHotCredential"); } std::vector @@ -173,6 +175,35 @@ AuthCommitteeHotCert::operator!=(const AuthCommitteeHotCert& other) const return !(*this == other); } +AuthCommitteeHotCert +AuthCommitteeHotCert::adopt(cardano_auth_committee_hot_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AuthCommitteeHotCert"); + } + + return AuthCommitteeHotCert(value); +} + +cardano_auth_committee_hot_cert_t* +AuthCommitteeHotCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_auth_committee_hot_cert_t* +AuthCommitteeHotCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_auth_committee_hot_cert_t* +AuthCommitteeHotCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AuthCommitteeHotCert::AuthCommitteeHotCert(cardano_auth_committee_hot_cert_t* value) noexcept diff --git a/lib/src/Certificates/Certificate.cpp b/lib/src/Certificates/Certificate.cpp index 7a059ae5..2fb4dee7 100644 --- a/lib/src/Certificates/Certificate.cpp +++ b/lib/src/Certificates/Certificate.cpp @@ -69,7 +69,7 @@ Certificate::Certificate(const AuthCommitteeHotCert& value) { const AuthCommitteeHotCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_auth_committee_hot(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_auth_committee_hot(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate AuthorizeCommitteeHot"); @@ -80,7 +80,7 @@ Certificate::Certificate(AuthCommitteeHotCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_auth_committee_hot(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_auth_committee_hot(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate AuthorizeCommitteeHot"); @@ -94,7 +94,7 @@ Certificate::Certificate(const GenesisKeyDelegationCert& value) { const GenesisKeyDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_genesis_key_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_genesis_key_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate GenesisKeyDelegation"); @@ -105,7 +105,7 @@ Certificate::Certificate(GenesisKeyDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_genesis_key_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_genesis_key_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate GenesisKeyDelegation"); @@ -119,7 +119,7 @@ Certificate::Certificate(const MirCert& value) { const MirCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_mir(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_mir(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate MoveInstantaneousRewards"); @@ -130,7 +130,7 @@ Certificate::Certificate(MirCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_mir(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_mir(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate MoveInstantaneousRewards"); @@ -144,7 +144,7 @@ Certificate::Certificate(const PoolRegistrationCert& value) { const PoolRegistrationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_pool_registration(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_pool_registration(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate PoolRegistration"); @@ -155,7 +155,7 @@ Certificate::Certificate(PoolRegistrationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_pool_registration(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_pool_registration(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate PoolRegistration"); @@ -169,7 +169,7 @@ Certificate::Certificate(const PoolRetirementCert& value) { const PoolRetirementCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_pool_retirement(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_pool_retirement(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate PoolRetirement"); @@ -180,7 +180,7 @@ Certificate::Certificate(PoolRetirementCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_pool_retirement(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_pool_retirement(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate PoolRetirement"); @@ -194,7 +194,7 @@ Certificate::Certificate(const RegisterDRepCert& value) { const RegisterDRepCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_register_drep(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_register_drep(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate DRepRegistration"); @@ -205,7 +205,7 @@ Certificate::Certificate(RegisterDRepCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_register_drep(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_register_drep(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate DRepRegistration"); @@ -219,7 +219,7 @@ Certificate::Certificate(const RegistrationCert& value) { const RegistrationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_registration(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_registration(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate Registration"); @@ -230,7 +230,7 @@ Certificate::Certificate(RegistrationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_registration(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_registration(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate Registration"); @@ -244,7 +244,7 @@ Certificate::Certificate(const ResignCommitteeColdCert& value) { const ResignCommitteeColdCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_resign_committee_cold(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_resign_committee_cold(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate ResignCommitteeCold"); @@ -255,7 +255,7 @@ Certificate::Certificate(ResignCommitteeColdCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_resign_committee_cold(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_resign_committee_cold(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate ResignCommitteeCold"); @@ -269,7 +269,7 @@ Certificate::Certificate(const StakeDelegationCert& value) { const StakeDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeDelegation"); @@ -280,7 +280,7 @@ Certificate::Certificate(StakeDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeDelegation"); @@ -294,7 +294,7 @@ Certificate::Certificate(const StakeDeregistrationCert& value) { const StakeDeregistrationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_deregistration(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_deregistration(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeDeregistration"); @@ -305,7 +305,7 @@ Certificate::Certificate(StakeDeregistrationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_deregistration(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_deregistration(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeDeregistration"); @@ -319,7 +319,7 @@ Certificate::Certificate(const StakeRegistrationCert& value) { const StakeRegistrationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_registration(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_registration(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeRegistration"); @@ -330,7 +330,7 @@ Certificate::Certificate(StakeRegistrationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_registration(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_registration(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeRegistration"); @@ -344,7 +344,7 @@ Certificate::Certificate(const StakeRegistrationDelegationCert& value) { const StakeRegistrationDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_registration_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_registration_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeRegistrationDelegation"); @@ -355,7 +355,7 @@ Certificate::Certificate(StakeRegistrationDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_registration_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_registration_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeRegistrationDelegation"); @@ -369,7 +369,7 @@ Certificate::Certificate(const StakeVoteDelegationCert& value) { const StakeVoteDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_vote_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_vote_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeVoteDelegation"); @@ -380,7 +380,7 @@ Certificate::Certificate(StakeVoteDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_vote_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_vote_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeVoteDelegation"); @@ -394,7 +394,7 @@ Certificate::Certificate(const StakeVoteRegistrationDelegationCert& value) { const StakeVoteRegistrationDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_vote_registration_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_vote_registration_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeVoteRegistrationDelegation"); @@ -405,7 +405,7 @@ Certificate::Certificate(StakeVoteRegistrationDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_stake_vote_registration_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_stake_vote_registration_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate StakeVoteRegistrationDelegation"); @@ -419,7 +419,7 @@ Certificate::Certificate(const UnregisterDRepCert& value) { const UnregisterDRepCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_unregister_drep(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_unregister_drep(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate DRepUnregistration"); @@ -430,7 +430,7 @@ Certificate::Certificate(UnregisterDRepCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_unregister_drep(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_unregister_drep(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate DRepUnregistration"); @@ -444,7 +444,7 @@ Certificate::Certificate(const UnregistrationCert& value) { const UnregistrationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_unregistration(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_unregistration(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate Unregistration"); @@ -455,7 +455,7 @@ Certificate::Certificate(UnregistrationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_unregistration(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_unregistration(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate Unregistration"); @@ -469,7 +469,7 @@ Certificate::Certificate(const UpdateDRepCert& value) { const UpdateDRepCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_update_drep(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_update_drep(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate UpdateDRep"); @@ -480,7 +480,7 @@ Certificate::Certificate(UpdateDRepCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_update_drep(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_update_drep(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate UpdateDRep"); @@ -494,7 +494,7 @@ Certificate::Certificate(const VoteDelegationCert& value) { const VoteDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_vote_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_vote_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate VoteDelegation"); @@ -505,7 +505,7 @@ Certificate::Certificate(VoteDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_vote_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_vote_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate VoteDelegation"); @@ -519,7 +519,7 @@ Certificate::Certificate(const VoteRegistrationDelegationCert& value) { const VoteRegistrationDelegationCert copy(value); cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_vote_registration_delegation(copy.checked(), &native); + const cardano_error_t status = cardano_certificate_new_vote_registration_delegation(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate VoteRegistrationDelegation"); @@ -530,7 +530,7 @@ Certificate::Certificate(VoteRegistrationDelegationCert&& value) : m_value(nullptr) { cardano_certificate_t* native = nullptr; - const cardano_error_t status = cardano_certificate_new_vote_registration_delegation(value.checked(), &native); + const cardano_error_t status = cardano_certificate_new_vote_registration_delegation(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "Certificate VoteRegistrationDelegation"); @@ -598,7 +598,7 @@ Certificate::asAuthCommitteeHot() const CardanoObject owner(native); checkCardanoError(status, "Certificate asAuthCommitteeHot"); - const AuthCommitteeHotCert value(owner.release()); + const AuthCommitteeHotCert value = AuthCommitteeHotCert::adopt(owner.release()); return AuthCommitteeHotCert(value); } @@ -615,7 +615,7 @@ Certificate::asGenesisKeyDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asGenesisKeyDelegation"); - const GenesisKeyDelegationCert value(owner.release()); + const GenesisKeyDelegationCert value = GenesisKeyDelegationCert::adopt(owner.release()); return GenesisKeyDelegationCert(value); } @@ -632,7 +632,7 @@ Certificate::asMir() const CardanoObject owner(native); checkCardanoError(status, "Certificate asMir"); - const MirCert value(owner.release()); + const MirCert value = MirCert::adopt(owner.release()); return MirCert(value); } @@ -649,7 +649,7 @@ Certificate::asPoolRegistration() const CardanoObject owner(native); checkCardanoError(status, "Certificate asPoolRegistration"); - const PoolRegistrationCert value(owner.release()); + const PoolRegistrationCert value = PoolRegistrationCert::adopt(owner.release()); return PoolRegistrationCert(value); } @@ -666,7 +666,7 @@ Certificate::asPoolRetirement() const CardanoObject owner(native); checkCardanoError(status, "Certificate asPoolRetirement"); - const PoolRetirementCert value(owner.release()); + const PoolRetirementCert value = PoolRetirementCert::adopt(owner.release()); return PoolRetirementCert(value); } @@ -683,7 +683,7 @@ Certificate::asRegisterDRep() const CardanoObject owner(native); checkCardanoError(status, "Certificate asRegisterDRep"); - const RegisterDRepCert value(owner.release()); + const RegisterDRepCert value = RegisterDRepCert::adopt(owner.release()); return RegisterDRepCert(value); } @@ -700,7 +700,7 @@ Certificate::asRegistration() const CardanoObject owner(native); checkCardanoError(status, "Certificate asRegistration"); - const RegistrationCert value(owner.release()); + const RegistrationCert value = RegistrationCert::adopt(owner.release()); return RegistrationCert(value); } @@ -717,7 +717,7 @@ Certificate::asResignCommitteeCold() const CardanoObject owner(native); checkCardanoError(status, "Certificate asResignCommitteeCold"); - const ResignCommitteeColdCert value(owner.release()); + const ResignCommitteeColdCert value = ResignCommitteeColdCert::adopt(owner.release()); return ResignCommitteeColdCert(value); } @@ -734,7 +734,7 @@ Certificate::asStakeDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeDelegation"); - const StakeDelegationCert value(owner.release()); + const StakeDelegationCert value = StakeDelegationCert::adopt(owner.release()); return StakeDelegationCert(value); } @@ -751,7 +751,7 @@ Certificate::asStakeDeregistration() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeDeregistration"); - const StakeDeregistrationCert value(owner.release()); + const StakeDeregistrationCert value = StakeDeregistrationCert::adopt(owner.release()); return StakeDeregistrationCert(value); } @@ -768,7 +768,7 @@ Certificate::asStakeRegistration() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeRegistration"); - const StakeRegistrationCert value(owner.release()); + const StakeRegistrationCert value = StakeRegistrationCert::adopt(owner.release()); return StakeRegistrationCert(value); } @@ -785,7 +785,7 @@ Certificate::asStakeRegistrationDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeRegistrationDelegation"); - const StakeRegistrationDelegationCert value(owner.release()); + const StakeRegistrationDelegationCert value = StakeRegistrationDelegationCert::adopt(owner.release()); return StakeRegistrationDelegationCert(value); } @@ -802,7 +802,7 @@ Certificate::asStakeVoteDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeVoteDelegation"); - const StakeVoteDelegationCert value(owner.release()); + const StakeVoteDelegationCert value = StakeVoteDelegationCert::adopt(owner.release()); return StakeVoteDelegationCert(value); } @@ -819,7 +819,7 @@ Certificate::asStakeVoteRegistrationDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asStakeVoteRegistrationDelegation"); - const StakeVoteRegistrationDelegationCert value(owner.release()); + const StakeVoteRegistrationDelegationCert value = StakeVoteRegistrationDelegationCert::adopt(owner.release()); return StakeVoteRegistrationDelegationCert(value); } @@ -836,7 +836,7 @@ Certificate::asUnregisterDRep() const CardanoObject owner(native); checkCardanoError(status, "Certificate asUnregisterDRep"); - const UnregisterDRepCert value(owner.release()); + const UnregisterDRepCert value = UnregisterDRepCert::adopt(owner.release()); return UnregisterDRepCert(value); } @@ -853,7 +853,7 @@ Certificate::asUnregistration() const CardanoObject owner(native); checkCardanoError(status, "Certificate asUnregistration"); - const UnregistrationCert value(owner.release()); + const UnregistrationCert value = UnregistrationCert::adopt(owner.release()); return UnregistrationCert(value); } @@ -870,7 +870,7 @@ Certificate::asUpdateDRep() const CardanoObject owner(native); checkCardanoError(status, "Certificate asUpdateDRep"); - const UpdateDRepCert value(owner.release()); + const UpdateDRepCert value = UpdateDRepCert::adopt(owner.release()); return UpdateDRepCert(value); } @@ -887,7 +887,7 @@ Certificate::asVoteDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asVoteDelegation"); - const VoteDelegationCert value(owner.release()); + const VoteDelegationCert value = VoteDelegationCert::adopt(owner.release()); return VoteDelegationCert(value); } @@ -904,7 +904,7 @@ Certificate::asVoteRegistrationDelegation() const CardanoObject owner(native); checkCardanoError(status, "Certificate asVoteRegistrationDelegation"); - const VoteRegistrationDelegationCert value(owner.release()); + const VoteRegistrationDelegationCert value = VoteRegistrationDelegationCert::adopt(owner.release()); return VoteRegistrationDelegationCert(value); } @@ -960,6 +960,35 @@ Certificate::operator!=(const Certificate& other) const return !(*this == other); } +Certificate +Certificate::adopt(cardano_certificate_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Certificate"); + } + + return Certificate(value); +} + +cardano_certificate_t* +Certificate::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_certificate_t* +Certificate::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_certificate_t* +Certificate::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Certificate::Certificate(cardano_certificate_t* value) noexcept diff --git a/lib/src/Certificates/CertificateSet.cpp b/lib/src/Certificates/CertificateSet.cpp index 4dc5c481..e9a8b671 100644 --- a/lib/src/Certificates/CertificateSet.cpp +++ b/lib/src/Certificates/CertificateSet.cpp @@ -33,6 +33,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -106,7 +108,7 @@ CertificateSet::add(const Certificate& value) } const Certificate copy(value); - checkCardanoError(cardano_certificate_set_add(checked(), copy.checked()), "CertificateSet add"); + checkCardanoError(cardano_certificate_set_add(checked(), checkedNativeHandle(copy)), "CertificateSet add"); } std::vector @@ -433,6 +435,60 @@ CertificateSet::empty() const return size() == 0; } +CertificateSet +CertificateSet::adopt(cardano_certificate_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CertificateSet"); + } + + return CertificateSet(value); +} + +cardano_certificate_set_t* +CertificateSet::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_certificate_set_t* +CertificateSet::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_certificate_set_t* +CertificateSet::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ CertificateSet::CertificateSet(cardano_certificate_set_t* value) noexcept @@ -523,7 +579,7 @@ CertificateSet::copyElement(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "CertificateSet at"); - const Certificate copied(owner.release()); + const Certificate copied = Certificate::adopt(owner.release()); return Certificate(copied); } diff --git a/lib/src/Certificates/GenesisKeyDelegationCert.cpp b/lib/src/Certificates/GenesisKeyDelegationCert.cpp index 72355af7..011c4731 100644 --- a/lib/src/Certificates/GenesisKeyDelegationCert.cpp +++ b/lib/src/Certificates/GenesisKeyDelegationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -44,7 +46,7 @@ GenesisKeyDelegationCert::GenesisKeyDelegationCert(const Blake2bHash& genesisHas const Blake2bHash delegateCopy(delegateHash); const Blake2bHash vrfCopy(vrfKeyHash); cardano_genesis_key_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_genesis_key_delegation_cert_new(genesisCopy.checked(), delegateCopy.checked(), vrfCopy.checked(), &value); + const cardano_error_t status = cardano_genesis_key_delegation_cert_new(checkedNativeHandle(genesisCopy), checkedNativeHandle(delegateCopy), checkedNativeHandle(vrfCopy), &value); CardanoObject owner(value); checkCardanoError(status, "GenesisKeyDelegationCert"); @@ -100,7 +102,7 @@ GenesisKeyDelegationCert::genesisHash() const throw std::logic_error("Genesis key delegation certificate has no genesis key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -109,7 +111,7 @@ GenesisKeyDelegationCert::setGenesisHash(const Blake2bHash& value) { validateHash(value, 28); const Blake2bHash copy(value); - checkCardanoError(cardano_genesis_key_delegation_cert_set_genesis_hash(checked(), copy.checked()), "GenesisKeyDelegationCert setGenesisHash"); + checkCardanoError(cardano_genesis_key_delegation_cert_set_genesis_hash(checked(), checkedNativeHandle(copy)), "GenesisKeyDelegationCert setGenesisHash"); } Blake2bHash @@ -121,7 +123,7 @@ GenesisKeyDelegationCert::delegateHash() const throw std::logic_error("Genesis key delegation certificate has no delegate key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -130,7 +132,7 @@ GenesisKeyDelegationCert::setDelegateHash(const Blake2bHash& value) { validateHash(value, 28); const Blake2bHash copy(value); - checkCardanoError(cardano_genesis_key_delegation_cert_set_genesis_delegate_hash(checked(), copy.checked()), "GenesisKeyDelegationCert setDelegateHash"); + checkCardanoError(cardano_genesis_key_delegation_cert_set_genesis_delegate_hash(checked(), checkedNativeHandle(copy)), "GenesisKeyDelegationCert setDelegateHash"); } Blake2bHash @@ -142,7 +144,7 @@ GenesisKeyDelegationCert::vrfKeyHash() const throw std::logic_error("Genesis key delegation certificate has no VRF key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -151,7 +153,7 @@ GenesisKeyDelegationCert::setVrfKeyHash(const Blake2bHash& value) { validateHash(value, 32); const Blake2bHash copy(value); - checkCardanoError(cardano_genesis_key_delegation_cert_set_vrf_key_hash(checked(), copy.checked()), "GenesisKeyDelegationCert setVrfKeyHash"); + checkCardanoError(cardano_genesis_key_delegation_cert_set_vrf_key_hash(checked(), checkedNativeHandle(copy)), "GenesisKeyDelegationCert setVrfKeyHash"); } std::vector @@ -208,6 +210,35 @@ GenesisKeyDelegationCert::operator!=(const GenesisKeyDelegationCert& other) cons return !(*this == other); } +GenesisKeyDelegationCert +GenesisKeyDelegationCert::adopt(cardano_genesis_key_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null GenesisKeyDelegationCert"); + } + + return GenesisKeyDelegationCert(value); +} + +cardano_genesis_key_delegation_cert_t* +GenesisKeyDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_genesis_key_delegation_cert_t* +GenesisKeyDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_genesis_key_delegation_cert_t* +GenesisKeyDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ GenesisKeyDelegationCert::GenesisKeyDelegationCert(cardano_genesis_key_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/MirCert.cpp b/lib/src/Certificates/MirCert.cpp index 6301afc3..c52e5bc6 100644 --- a/lib/src/Certificates/MirCert.cpp +++ b/lib/src/Certificates/MirCert.cpp @@ -42,7 +42,7 @@ MirCert::MirCert(const MirToPotCert& value) { MirToPotCert copy(value); cardano_mir_cert_t* native = nullptr; - const cardano_error_t status = cardano_mir_cert_new_to_other_pot(copy.checked(), &native); + const cardano_error_t status = cardano_mir_cert_new_to_other_pot(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "MirCert pot transfer"); @@ -53,7 +53,7 @@ MirCert::MirCert(MirToPotCert&& value) : m_value(nullptr) { cardano_mir_cert_t* native = nullptr; - const cardano_error_t status = cardano_mir_cert_new_to_other_pot(value.checked(), &native); + const cardano_error_t status = cardano_mir_cert_new_to_other_pot(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "MirCert pot transfer"); @@ -67,7 +67,7 @@ MirCert::MirCert(const MirToStakeCredentialsCert& value) { MirToStakeCredentialsCert copy(value); cardano_mir_cert_t* native = nullptr; - const cardano_error_t status = cardano_mir_cert_new_to_stake_creds(copy.checked(), &native); + const cardano_error_t status = cardano_mir_cert_new_to_stake_creds(checkedNativeHandle(copy), &native); CardanoObject owner(native); checkCardanoError(status, "MirCert stake distribution"); @@ -78,7 +78,7 @@ MirCert::MirCert(MirToStakeCredentialsCert&& value) : m_value(nullptr) { cardano_mir_cert_t* native = nullptr; - const cardano_error_t status = cardano_mir_cert_new_to_stake_creds(value.checked(), &native); + const cardano_error_t status = cardano_mir_cert_new_to_stake_creds(checkedNativeHandle(value), &native); CardanoObject owner(native); checkCardanoError(status, "MirCert stake distribution"); @@ -148,7 +148,7 @@ MirCert::asToPot() const CardanoObject owner(native); checkCardanoError(status, "MirCert asToPot"); - MirToPotCert value(owner.release()); + MirToPotCert value = MirToPotCert::adopt(owner.release()); return MirToPotCert(value); } @@ -165,7 +165,7 @@ MirCert::asToStakeCredentials() const CardanoObject owner(native); checkCardanoError(status, "MirCert asToStakeCredentials"); - MirToStakeCredentialsCert value(owner.release()); + MirToStakeCredentialsCert value = MirToStakeCredentialsCert::adopt(owner.release()); return MirToStakeCredentialsCert(value); } @@ -221,6 +221,35 @@ MirCert::operator!=(const MirCert& other) const return !(*this == other); } +MirCert +MirCert::adopt(cardano_mir_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MirCert"); + } + + return MirCert(value); +} + +cardano_mir_cert_t* +MirCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_mir_cert_t* +MirCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_mir_cert_t* +MirCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MirCert::MirCert(cardano_mir_cert_t* value) noexcept diff --git a/lib/src/Certificates/MirToPotCert.cpp b/lib/src/Certificates/MirToPotCert.cpp index c6277f7e..64e048c4 100644 --- a/lib/src/Certificates/MirToPotCert.cpp +++ b/lib/src/Certificates/MirToPotCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -162,6 +164,35 @@ MirToPotCert::operator!=(const MirToPotCert& other) const return !(*this == other); } +MirToPotCert +MirToPotCert::adopt(cardano_mir_to_pot_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MirToPotCert"); + } + + return MirToPotCert(value); +} + +cardano_mir_to_pot_cert_t* +MirToPotCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_mir_to_pot_cert_t* +MirToPotCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_mir_to_pot_cert_t* +MirToPotCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MirToPotCert::MirToPotCert(cardano_mir_to_pot_cert_t* value) noexcept diff --git a/lib/src/Certificates/MirToStakeCredentialsCert.cpp b/lib/src/Certificates/MirToStakeCredentialsCert.cpp index cb5dd6ff..dc693504 100644 --- a/lib/src/Certificates/MirToStakeCredentialsCert.cpp +++ b/lib/src/Certificates/MirToStakeCredentialsCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -106,7 +108,7 @@ MirToStakeCredentialsCert::size() const void MirToStakeCredentialsCert::insert(const Credential& credential, std::uint64_t amount) { - checkCardanoError(cardano_mir_to_stake_creds_cert_insert(checked(), credential.checked(), amount), "MirToStakeCredentialsCert insert"); + checkCardanoError(cardano_mir_to_stake_creds_cert_insert(checked(), checkedNativeHandle(credential), amount), "MirToStakeCredentialsCert insert"); } std::pair @@ -123,7 +125,7 @@ MirToStakeCredentialsCert::at(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "MirToStakeCredentialsCert at"); - Credential copied(owner.release()); + Credential copied = Credential::adopt(owner.release()); return std::make_pair(Credential(copied), amount); } @@ -179,6 +181,35 @@ MirToStakeCredentialsCert::operator!=(const MirToStakeCredentialsCert& other) co return !(*this == other); } +MirToStakeCredentialsCert +MirToStakeCredentialsCert::adopt(cardano_mir_to_stake_creds_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MirToStakeCredentialsCert"); + } + + return MirToStakeCredentialsCert(value); +} + +cardano_mir_to_stake_creds_cert_t* +MirToStakeCredentialsCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_mir_to_stake_creds_cert_t* +MirToStakeCredentialsCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_mir_to_stake_creds_cert_t* +MirToStakeCredentialsCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MirToStakeCredentialsCert::MirToStakeCredentialsCert(cardano_mir_to_stake_creds_cert_t* value) noexcept diff --git a/lib/src/Certificates/PoolRegistrationCert.cpp b/lib/src/Certificates/PoolRegistrationCert.cpp index 1e5d5bad..46e6b5c1 100644 --- a/lib/src/Certificates/PoolRegistrationCert.cpp +++ b/lib/src/Certificates/PoolRegistrationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ PoolRegistrationCert::PoolRegistrationCert(const PoolParams& params) { const PoolParams copy(params); cardano_pool_registration_cert_t* value = nullptr; - const cardano_error_t status = cardano_pool_registration_cert_new(copy.checked(), &value); + const cardano_error_t status = cardano_pool_registration_cert_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); checkCardanoError(status, "PoolRegistrationCert"); @@ -87,7 +89,7 @@ PoolRegistrationCert::params() const CardanoObject owner(value); checkCardanoError(status, "PoolRegistrationCert params"); - const PoolParams result(owner.release()); + const PoolParams result = PoolParams::adopt(owner.release()); return PoolParams(result); } @@ -95,7 +97,7 @@ void PoolRegistrationCert::setParams(const PoolParams& value) { const PoolParams copy(value); - checkCardanoError(cardano_pool_registration_cert_set_params(checked(), copy.checked()), "PoolRegistrationCert setParams"); + checkCardanoError(cardano_pool_registration_cert_set_params(checked(), checkedNativeHandle(copy)), "PoolRegistrationCert setParams"); } std::vector @@ -152,6 +154,35 @@ PoolRegistrationCert::operator!=(const PoolRegistrationCert& other) const return !(*this == other); } +PoolRegistrationCert +PoolRegistrationCert::adopt(cardano_pool_registration_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolRegistrationCert"); + } + + return PoolRegistrationCert(value); +} + +cardano_pool_registration_cert_t* +PoolRegistrationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pool_registration_cert_t* +PoolRegistrationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_registration_cert_t* +PoolRegistrationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolRegistrationCert::PoolRegistrationCert(cardano_pool_registration_cert_t* value) noexcept diff --git a/lib/src/Certificates/PoolRetirementCert.cpp b/lib/src/Certificates/PoolRetirementCert.cpp index 504413a1..a5478330 100644 --- a/lib/src/Certificates/PoolRetirementCert.cpp +++ b/lib/src/Certificates/PoolRetirementCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -43,7 +45,7 @@ PoolRetirementCert::PoolRetirementCert(const Blake2bHash& poolKeyHash, std::uint const Blake2bHash copy(poolKeyHash); cardano_pool_retirement_cert_t* value = nullptr; - const cardano_error_t status = cardano_pool_retirement_cert_new(copy.checked(), epoch, &value); + const cardano_error_t status = cardano_pool_retirement_cert_new(checkedNativeHandle(copy), epoch, &value); CardanoObject owner(value); checkCardanoError(status, "PoolRetirementCert"); @@ -99,7 +101,7 @@ PoolRetirementCert::poolKeyHash() const throw std::logic_error("Pool retirement certificate has no pool key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -112,7 +114,7 @@ PoolRetirementCert::setPoolKeyHash(const Blake2bHash& value) } const Blake2bHash copy(value); - checkCardanoError(cardano_pool_retirement_cert_set_pool_key_hash(checked(), copy.checked()), "PoolRetirementCert setPoolKeyHash"); + checkCardanoError(cardano_pool_retirement_cert_set_pool_key_hash(checked(), checkedNativeHandle(copy)), "PoolRetirementCert setPoolKeyHash"); } std::uint64_t @@ -181,6 +183,35 @@ PoolRetirementCert::operator!=(const PoolRetirementCert& other) const return !(*this == other); } +PoolRetirementCert +PoolRetirementCert::adopt(cardano_pool_retirement_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolRetirementCert"); + } + + return PoolRetirementCert(value); +} + +cardano_pool_retirement_cert_t* +PoolRetirementCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pool_retirement_cert_t* +PoolRetirementCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_retirement_cert_t* +PoolRetirementCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolRetirementCert::PoolRetirementCert(cardano_pool_retirement_cert_t* value) noexcept diff --git a/lib/src/Certificates/RegisterDRepCert.cpp b/lib/src/Certificates/RegisterDRepCert.cpp index cc136bf1..91772b5c 100644 --- a/lib/src/Certificates/RegisterDRepCert.cpp +++ b/lib/src/Certificates/RegisterDRepCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -39,7 +41,7 @@ RegisterDRepCert::RegisterDRepCert(const Credential& credential, std::uint64_t d { const Credential copy(credential); cardano_register_drep_cert_t* value = nullptr; - const cardano_error_t status = cardano_register_drep_cert_new(copy.checked(), deposit, anchor ? anchor->checked() : nullptr, &value); + const cardano_error_t status = cardano_register_drep_cert_new(checkedNativeHandle(copy), deposit, anchor ? checkedNativeHandle(*anchor) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "RegisterDRepCert"); @@ -89,7 +91,7 @@ RegisterDRepCert::credential() const throw std::logic_error("DRep registration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -97,7 +99,7 @@ void RegisterDRepCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_register_drep_cert_set_credential(checked(), copy.checked()), "RegisterDRepCert setCredential"); + checkCardanoError(cardano_register_drep_cert_set_credential(checked(), checkedNativeHandle(copy)), "RegisterDRepCert setCredential"); } std::uint64_t @@ -121,7 +123,7 @@ RegisterDRepCert::anchor() const return std::nullopt; } - const Anchor result(value); + const Anchor result = Anchor::adopt(value); return Anchor(result); } @@ -186,6 +188,35 @@ RegisterDRepCert::operator!=(const RegisterDRepCert& other) const return !(*this == other); } +RegisterDRepCert +RegisterDRepCert::adopt(cardano_register_drep_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null RegisterDRepCert"); + } + + return RegisterDRepCert(value); +} + +cardano_register_drep_cert_t* +RegisterDRepCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_register_drep_cert_t* +RegisterDRepCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_register_drep_cert_t* +RegisterDRepCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ RegisterDRepCert::RegisterDRepCert(cardano_register_drep_cert_t* value) noexcept diff --git a/lib/src/Certificates/RegistrationCert.cpp b/lib/src/Certificates/RegistrationCert.cpp index 667cf39d..7907a8aa 100644 --- a/lib/src/Certificates/RegistrationCert.cpp +++ b/lib/src/Certificates/RegistrationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ RegistrationCert::RegistrationCert(const Credential& credential, std::uint64_t d { const Credential copy(credential); cardano_registration_cert_t* value = nullptr; - const cardano_error_t status = cardano_registration_cert_new(copy.checked(), deposit, &value); + const cardano_error_t status = cardano_registration_cert_new(checkedNativeHandle(copy), deposit, &value); CardanoObject owner(value); checkCardanoError(status, "RegistrationCert"); @@ -88,7 +90,7 @@ RegistrationCert::credential() const throw std::logic_error("Registration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -96,7 +98,7 @@ void RegistrationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_registration_cert_set_stake_credential(checked(), copy.checked()), "RegistrationCert setCredential"); + checkCardanoError(cardano_registration_cert_set_stake_credential(checked(), checkedNativeHandle(copy)), "RegistrationCert setCredential"); } std::uint64_t @@ -165,6 +167,35 @@ RegistrationCert::operator!=(const RegistrationCert& other) const return !(*this == other); } +RegistrationCert +RegistrationCert::adopt(cardano_registration_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null RegistrationCert"); + } + + return RegistrationCert(value); +} + +cardano_registration_cert_t* +RegistrationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_registration_cert_t* +RegistrationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_registration_cert_t* +RegistrationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ RegistrationCert::RegistrationCert(cardano_registration_cert_t* value) noexcept diff --git a/lib/src/Certificates/ResignCommitteeColdCert.cpp b/lib/src/Certificates/ResignCommitteeColdCert.cpp index 7e3f4e3c..a73f7f95 100644 --- a/lib/src/Certificates/ResignCommitteeColdCert.cpp +++ b/lib/src/Certificates/ResignCommitteeColdCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -39,7 +41,7 @@ ResignCommitteeColdCert::ResignCommitteeColdCert(const Credential& credential, s { const Credential copy(credential); cardano_resign_committee_cold_cert_t* value = nullptr; - const cardano_error_t status = cardano_resign_committee_cold_cert_new(copy.checked(), anchor ? anchor->checked() : nullptr, &value); + const cardano_error_t status = cardano_resign_committee_cold_cert_new(checkedNativeHandle(copy), anchor ? checkedNativeHandle(*anchor) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "ResignCommitteeColdCert"); @@ -89,7 +91,7 @@ ResignCommitteeColdCert::credential() const throw std::logic_error("Committee resignation certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -97,7 +99,7 @@ void ResignCommitteeColdCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_resign_committee_cold_cert_set_credential(checked(), copy.checked()), "ResignCommitteeColdCert setCredential"); + checkCardanoError(cardano_resign_committee_cold_cert_set_credential(checked(), checkedNativeHandle(copy)), "ResignCommitteeColdCert setCredential"); } std::optional @@ -109,7 +111,7 @@ ResignCommitteeColdCert::anchor() const return std::nullopt; } - const Anchor result(value); + const Anchor result = Anchor::adopt(value); return Anchor(result); } @@ -174,6 +176,35 @@ ResignCommitteeColdCert::operator!=(const ResignCommitteeColdCert& other) const return !(*this == other); } +ResignCommitteeColdCert +ResignCommitteeColdCert::adopt(cardano_resign_committee_cold_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ResignCommitteeColdCert"); + } + + return ResignCommitteeColdCert(value); +} + +cardano_resign_committee_cold_cert_t* +ResignCommitteeColdCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_resign_committee_cold_cert_t* +ResignCommitteeColdCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_resign_committee_cold_cert_t* +ResignCommitteeColdCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ResignCommitteeColdCert::ResignCommitteeColdCert(cardano_resign_committee_cold_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeDelegationCert.cpp b/lib/src/Certificates/StakeDelegationCert.cpp index 8b04696c..57300a57 100644 --- a/lib/src/Certificates/StakeDelegationCert.cpp +++ b/lib/src/Certificates/StakeDelegationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -44,7 +46,7 @@ StakeDelegationCert::StakeDelegationCert(const Credential& credential, const Bla const Credential copy(credential); const Blake2bHash poolCopy(poolKeyHash); cardano_stake_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_delegation_cert_new(copy.checked(), poolCopy.checked(), &value); + const cardano_error_t status = cardano_stake_delegation_cert_new(checkedNativeHandle(copy), checkedNativeHandle(poolCopy), &value); CardanoObject owner(value); checkCardanoError(status, "StakeDelegationCert"); @@ -94,7 +96,7 @@ StakeDelegationCert::credential() const throw std::logic_error("Stake registration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -102,7 +104,7 @@ void StakeDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_delegation_cert_set_credential(checked(), copy.checked()), "StakeDelegationCert setCredential"); + checkCardanoError(cardano_stake_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeDelegationCert setCredential"); } Blake2bHash @@ -114,7 +116,7 @@ StakeDelegationCert::poolKeyHash() const throw std::logic_error("Stake delegation certificate has no pool key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -127,7 +129,7 @@ StakeDelegationCert::setPoolKeyHash(const Blake2bHash& value) } const Blake2bHash copy(value); - checkCardanoError(cardano_stake_delegation_cert_set_pool_key_hash(checked(), copy.checked()), "StakeDelegationCert setPoolKeyHash"); + checkCardanoError(cardano_stake_delegation_cert_set_pool_key_hash(checked(), checkedNativeHandle(copy)), "StakeDelegationCert setPoolKeyHash"); } std::vector @@ -184,6 +186,35 @@ StakeDelegationCert::operator!=(const StakeDelegationCert& other) const return !(*this == other); } +StakeDelegationCert +StakeDelegationCert::adopt(cardano_stake_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeDelegationCert"); + } + + return StakeDelegationCert(value); +} + +cardano_stake_delegation_cert_t* +StakeDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_delegation_cert_t* +StakeDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_delegation_cert_t* +StakeDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeDelegationCert::StakeDelegationCert(cardano_stake_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeDeregistrationCert.cpp b/lib/src/Certificates/StakeDeregistrationCert.cpp index a06c3977..8231266b 100644 --- a/lib/src/Certificates/StakeDeregistrationCert.cpp +++ b/lib/src/Certificates/StakeDeregistrationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ StakeDeregistrationCert::StakeDeregistrationCert(const Credential& credential) { const Credential copy(credential); cardano_stake_deregistration_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_deregistration_cert_new(copy.checked(), &value); + const cardano_error_t status = cardano_stake_deregistration_cert_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); checkCardanoError(status, "StakeDeregistrationCert"); @@ -88,7 +90,7 @@ StakeDeregistrationCert::credential() const throw std::logic_error("Stake deregistration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -96,7 +98,7 @@ void StakeDeregistrationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_deregistration_cert_set_credential(checked(), copy.checked()), "StakeDeregistrationCert setCredential"); + checkCardanoError(cardano_stake_deregistration_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeDeregistrationCert setCredential"); } std::vector @@ -153,6 +155,35 @@ StakeDeregistrationCert::operator!=(const StakeDeregistrationCert& other) const return !(*this == other); } +StakeDeregistrationCert +StakeDeregistrationCert::adopt(cardano_stake_deregistration_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeDeregistrationCert"); + } + + return StakeDeregistrationCert(value); +} + +cardano_stake_deregistration_cert_t* +StakeDeregistrationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_deregistration_cert_t* +StakeDeregistrationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_deregistration_cert_t* +StakeDeregistrationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeDeregistrationCert::StakeDeregistrationCert(cardano_stake_deregistration_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeRegistrationCert.cpp b/lib/src/Certificates/StakeRegistrationCert.cpp index 95941643..c770d758 100644 --- a/lib/src/Certificates/StakeRegistrationCert.cpp +++ b/lib/src/Certificates/StakeRegistrationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ StakeRegistrationCert::StakeRegistrationCert(const Credential& credential) { const Credential copy(credential); cardano_stake_registration_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_registration_cert_new(copy.checked(), &value); + const cardano_error_t status = cardano_stake_registration_cert_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); checkCardanoError(status, "StakeRegistrationCert"); @@ -88,7 +90,7 @@ StakeRegistrationCert::credential() const throw std::logic_error("Stake registration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -96,7 +98,7 @@ void StakeRegistrationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_registration_cert_set_credential(checked(), copy.checked()), "StakeRegistrationCert setCredential"); + checkCardanoError(cardano_stake_registration_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeRegistrationCert setCredential"); } std::vector @@ -153,6 +155,35 @@ StakeRegistrationCert::operator!=(const StakeRegistrationCert& other) const return !(*this == other); } +StakeRegistrationCert +StakeRegistrationCert::adopt(cardano_stake_registration_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeRegistrationCert"); + } + + return StakeRegistrationCert(value); +} + +cardano_stake_registration_cert_t* +StakeRegistrationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_registration_cert_t* +StakeRegistrationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_registration_cert_t* +StakeRegistrationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeRegistrationCert::StakeRegistrationCert(cardano_stake_registration_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeRegistrationDelegationCert.cpp b/lib/src/Certificates/StakeRegistrationDelegationCert.cpp index 12267c79..9517e46e 100644 --- a/lib/src/Certificates/StakeRegistrationDelegationCert.cpp +++ b/lib/src/Certificates/StakeRegistrationDelegationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -44,7 +46,7 @@ StakeRegistrationDelegationCert::StakeRegistrationDelegationCert(const Credentia const Credential copy(credential); const Blake2bHash poolCopy(poolKeyHash); cardano_stake_registration_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_registration_delegation_cert_new(copy.checked(), poolCopy.checked(), deposit, &value); + const cardano_error_t status = cardano_stake_registration_delegation_cert_new(checkedNativeHandle(copy), checkedNativeHandle(poolCopy), deposit, &value); CardanoObject owner(value); checkCardanoError(status, "StakeRegistrationDelegationCert"); @@ -94,7 +96,7 @@ StakeRegistrationDelegationCert::credential() const throw std::logic_error("Stake registration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -102,7 +104,7 @@ void StakeRegistrationDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_registration_delegation_cert_set_credential(checked(), copy.checked()), "StakeRegistrationDelegationCert setCredential"); + checkCardanoError(cardano_stake_registration_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeRegistrationDelegationCert setCredential"); } Blake2bHash @@ -114,7 +116,7 @@ StakeRegistrationDelegationCert::poolKeyHash() const throw std::logic_error("Stake registration and delegation certificate has no pool key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -127,7 +129,7 @@ StakeRegistrationDelegationCert::setPoolKeyHash(const Blake2bHash& value) } const Blake2bHash copy(value); - checkCardanoError(cardano_stake_registration_delegation_cert_set_pool_key_hash(checked(), copy.checked()), "StakeRegistrationDelegationCert setPoolKeyHash"); + checkCardanoError(cardano_stake_registration_delegation_cert_set_pool_key_hash(checked(), checkedNativeHandle(copy)), "StakeRegistrationDelegationCert setPoolKeyHash"); } std::uint64_t @@ -196,6 +198,35 @@ StakeRegistrationDelegationCert::operator!=(const StakeRegistrationDelegationCer return !(*this == other); } +StakeRegistrationDelegationCert +StakeRegistrationDelegationCert::adopt(cardano_stake_registration_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeRegistrationDelegationCert"); + } + + return StakeRegistrationDelegationCert(value); +} + +cardano_stake_registration_delegation_cert_t* +StakeRegistrationDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_registration_delegation_cert_t* +StakeRegistrationDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_registration_delegation_cert_t* +StakeRegistrationDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeRegistrationDelegationCert::StakeRegistrationDelegationCert(cardano_stake_registration_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeVoteDelegationCert.cpp b/lib/src/Certificates/StakeVoteDelegationCert.cpp index 734203d6..dba2596c 100644 --- a/lib/src/Certificates/StakeVoteDelegationCert.cpp +++ b/lib/src/Certificates/StakeVoteDelegationCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -46,7 +48,7 @@ StakeVoteDelegationCert::StakeVoteDelegationCert(const Credential& credential, c const Blake2bHash poolCopy(poolKeyHash); const DRep drepCopy(drep); cardano_stake_vote_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_vote_delegation_cert_new(copy.checked(), poolCopy.checked(), drepCopy.checked(), &value); + const cardano_error_t status = cardano_stake_vote_delegation_cert_new(checkedNativeHandle(copy), checkedNativeHandle(poolCopy), checkedNativeHandle(drepCopy), &value); CardanoObject owner(value); checkCardanoError(status, "StakeVoteDelegationCert"); @@ -96,7 +98,7 @@ StakeVoteDelegationCert::credential() const throw std::logic_error("Stake and vote delegation certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -104,7 +106,7 @@ void StakeVoteDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_vote_delegation_cert_set_credential(checked(), copy.checked()), "StakeVoteDelegationCert setCredential"); + checkCardanoError(cardano_stake_vote_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeVoteDelegationCert setCredential"); } Blake2bHash @@ -116,7 +118,7 @@ StakeVoteDelegationCert::poolKeyHash() const throw std::logic_error("Stake and vote delegation certificate has no pool key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -129,7 +131,7 @@ StakeVoteDelegationCert::setPoolKeyHash(const Blake2bHash& value) } const Blake2bHash copy(value); - checkCardanoError(cardano_stake_vote_delegation_cert_set_pool_key_hash(checked(), copy.checked()), "StakeVoteDelegationCert setPoolKeyHash"); + checkCardanoError(cardano_stake_vote_delegation_cert_set_pool_key_hash(checked(), checkedNativeHandle(copy)), "StakeVoteDelegationCert setPoolKeyHash"); } DRep @@ -141,7 +143,7 @@ StakeVoteDelegationCert::drep() const throw std::logic_error("Stake and vote delegation certificate has no DRep"); } - const DRep result(value); + const DRep result = DRep::adopt(value); return DRep(result); } @@ -149,7 +151,7 @@ void StakeVoteDelegationCert::setDRep(const DRep& value) { const DRep copy(value); - checkCardanoError(cardano_stake_vote_delegation_cert_set_drep(checked(), copy.checked()), "StakeVoteDelegationCert setDRep"); + checkCardanoError(cardano_stake_vote_delegation_cert_set_drep(checked(), checkedNativeHandle(copy)), "StakeVoteDelegationCert setDRep"); } std::vector @@ -206,6 +208,35 @@ StakeVoteDelegationCert::operator!=(const StakeVoteDelegationCert& other) const return !(*this == other); } +StakeVoteDelegationCert +StakeVoteDelegationCert::adopt(cardano_stake_vote_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeVoteDelegationCert"); + } + + return StakeVoteDelegationCert(value); +} + +cardano_stake_vote_delegation_cert_t* +StakeVoteDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_vote_delegation_cert_t* +StakeVoteDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_vote_delegation_cert_t* +StakeVoteDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeVoteDelegationCert::StakeVoteDelegationCert(cardano_stake_vote_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/StakeVoteRegistrationDelegationCert.cpp b/lib/src/Certificates/StakeVoteRegistrationDelegationCert.cpp index 292a0223..1ebce570 100644 --- a/lib/src/Certificates/StakeVoteRegistrationDelegationCert.cpp +++ b/lib/src/Certificates/StakeVoteRegistrationDelegationCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -46,7 +48,7 @@ StakeVoteRegistrationDelegationCert::StakeVoteRegistrationDelegationCert(const C const Blake2bHash poolCopy(poolKeyHash); const DRep drepCopy(drep); cardano_stake_vote_registration_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_stake_vote_registration_delegation_cert_new(copy.checked(), deposit, drepCopy.checked(), poolCopy.checked(), &value); + const cardano_error_t status = cardano_stake_vote_registration_delegation_cert_new(checkedNativeHandle(copy), deposit, checkedNativeHandle(drepCopy), checkedNativeHandle(poolCopy), &value); CardanoObject owner(value); checkCardanoError(status, "StakeVoteRegistrationDelegationCert"); @@ -96,7 +98,7 @@ StakeVoteRegistrationDelegationCert::credential() const throw std::logic_error("Stake and vote delegation certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -104,7 +106,7 @@ void StakeVoteRegistrationDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_credential(checked(), copy.checked()), "StakeVoteRegistrationDelegationCert setCredential"); + checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "StakeVoteRegistrationDelegationCert setCredential"); } Blake2bHash @@ -116,7 +118,7 @@ StakeVoteRegistrationDelegationCert::poolKeyHash() const throw std::logic_error("Stake and vote delegation certificate has no pool key hash"); } - const Blake2bHash result(value); + const Blake2bHash result = Blake2bHash::adopt(value); return Blake2bHash(result); } @@ -129,7 +131,7 @@ StakeVoteRegistrationDelegationCert::setPoolKeyHash(const Blake2bHash& value) } const Blake2bHash copy(value); - checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_pool_key_hash(checked(), copy.checked()), "StakeVoteRegistrationDelegationCert setPoolKeyHash"); + checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_pool_key_hash(checked(), checkedNativeHandle(copy)), "StakeVoteRegistrationDelegationCert setPoolKeyHash"); } DRep @@ -141,7 +143,7 @@ StakeVoteRegistrationDelegationCert::drep() const throw std::logic_error("Stake and vote delegation certificate has no DRep"); } - const DRep result(value); + const DRep result = DRep::adopt(value); return DRep(result); } @@ -149,7 +151,7 @@ void StakeVoteRegistrationDelegationCert::setDRep(const DRep& value) { const DRep copy(value); - checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_drep(checked(), copy.checked()), "StakeVoteRegistrationDelegationCert setDRep"); + checkCardanoError(cardano_stake_vote_registration_delegation_cert_set_drep(checked(), checkedNativeHandle(copy)), "StakeVoteRegistrationDelegationCert setDRep"); } std::uint64_t @@ -218,6 +220,35 @@ StakeVoteRegistrationDelegationCert::operator!=(const StakeVoteRegistrationDeleg return !(*this == other); } +StakeVoteRegistrationDelegationCert +StakeVoteRegistrationDelegationCert::adopt(cardano_stake_vote_registration_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null StakeVoteRegistrationDelegationCert"); + } + + return StakeVoteRegistrationDelegationCert(value); +} + +cardano_stake_vote_registration_delegation_cert_t* +StakeVoteRegistrationDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_stake_vote_registration_delegation_cert_t* +StakeVoteRegistrationDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_stake_vote_registration_delegation_cert_t* +StakeVoteRegistrationDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ StakeVoteRegistrationDelegationCert::StakeVoteRegistrationDelegationCert(cardano_stake_vote_registration_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/UnregisterDRepCert.cpp b/lib/src/Certificates/UnregisterDRepCert.cpp index b5446579..37bd6bfe 100644 --- a/lib/src/Certificates/UnregisterDRepCert.cpp +++ b/lib/src/Certificates/UnregisterDRepCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ UnregisterDRepCert::UnregisterDRepCert(const Credential& credential, std::uint64 { const Credential copy(credential); cardano_unregister_drep_cert_t* value = nullptr; - const cardano_error_t status = cardano_unregister_drep_cert_new(copy.checked(), deposit, &value); + const cardano_error_t status = cardano_unregister_drep_cert_new(checkedNativeHandle(copy), deposit, &value); CardanoObject owner(value); checkCardanoError(status, "UnregisterDRepCert"); @@ -88,7 +90,7 @@ UnregisterDRepCert::credential() const throw std::logic_error("DRep unregistration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -96,7 +98,7 @@ void UnregisterDRepCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_unregister_drep_cert_set_credential(checked(), copy.checked()), "UnregisterDRepCert setCredential"); + checkCardanoError(cardano_unregister_drep_cert_set_credential(checked(), checkedNativeHandle(copy)), "UnregisterDRepCert setCredential"); } std::uint64_t @@ -165,6 +167,35 @@ UnregisterDRepCert::operator!=(const UnregisterDRepCert& other) const return !(*this == other); } +UnregisterDRepCert +UnregisterDRepCert::adopt(cardano_unregister_drep_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null UnregisterDRepCert"); + } + + return UnregisterDRepCert(value); +} + +cardano_unregister_drep_cert_t* +UnregisterDRepCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_unregister_drep_cert_t* +UnregisterDRepCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_unregister_drep_cert_t* +UnregisterDRepCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ UnregisterDRepCert::UnregisterDRepCert(cardano_unregister_drep_cert_t* value) noexcept diff --git a/lib/src/Certificates/UnregistrationCert.cpp b/lib/src/Certificates/UnregistrationCert.cpp index 01d38468..6e073ce6 100644 --- a/lib/src/Certificates/UnregistrationCert.cpp +++ b/lib/src/Certificates/UnregistrationCert.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ UnregistrationCert::UnregistrationCert(const Credential& credential, std::uint64 { const Credential copy(credential); cardano_unregistration_cert_t* value = nullptr; - const cardano_error_t status = cardano_unregistration_cert_new(copy.checked(), deposit, &value); + const cardano_error_t status = cardano_unregistration_cert_new(checkedNativeHandle(copy), deposit, &value); CardanoObject owner(value); checkCardanoError(status, "UnregistrationCert"); @@ -88,7 +90,7 @@ UnregistrationCert::credential() const throw std::logic_error("Unregistration certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -96,7 +98,7 @@ void UnregistrationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_unregistration_cert_set_credential(checked(), copy.checked()), "UnregistrationCert setCredential"); + checkCardanoError(cardano_unregistration_cert_set_credential(checked(), checkedNativeHandle(copy)), "UnregistrationCert setCredential"); } std::uint64_t @@ -165,6 +167,35 @@ UnregistrationCert::operator!=(const UnregistrationCert& other) const return !(*this == other); } +UnregistrationCert +UnregistrationCert::adopt(cardano_unregistration_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null UnregistrationCert"); + } + + return UnregistrationCert(value); +} + +cardano_unregistration_cert_t* +UnregistrationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_unregistration_cert_t* +UnregistrationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_unregistration_cert_t* +UnregistrationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ UnregistrationCert::UnregistrationCert(cardano_unregistration_cert_t* value) noexcept diff --git a/lib/src/Certificates/UpdateDRepCert.cpp b/lib/src/Certificates/UpdateDRepCert.cpp index 00389e4b..9fc1ebba 100644 --- a/lib/src/Certificates/UpdateDRepCert.cpp +++ b/lib/src/Certificates/UpdateDRepCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -39,7 +41,7 @@ UpdateDRepCert::UpdateDRepCert(const Credential& credential, std::optionalchecked() : nullptr, &value); + const cardano_error_t status = cardano_update_drep_cert_new(checkedNativeHandle(copy), anchor ? checkedNativeHandle(*anchor) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "UpdateDRepCert"); @@ -89,7 +91,7 @@ UpdateDRepCert::credential() const throw std::logic_error("DRep update certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -97,7 +99,7 @@ void UpdateDRepCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_update_drep_cert_set_credential(checked(), copy.checked()), "UpdateDRepCert setCredential"); + checkCardanoError(cardano_update_drep_cert_set_credential(checked(), checkedNativeHandle(copy)), "UpdateDRepCert setCredential"); } std::optional @@ -109,7 +111,7 @@ UpdateDRepCert::anchor() const return std::nullopt; } - const Anchor result(value); + const Anchor result = Anchor::adopt(value); return Anchor(result); } @@ -174,6 +176,35 @@ UpdateDRepCert::operator!=(const UpdateDRepCert& other) const return !(*this == other); } +UpdateDRepCert +UpdateDRepCert::adopt(cardano_update_drep_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null UpdateDRepCert"); + } + + return UpdateDRepCert(value); +} + +cardano_update_drep_cert_t* +UpdateDRepCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_update_drep_cert_t* +UpdateDRepCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_update_drep_cert_t* +UpdateDRepCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ UpdateDRepCert::UpdateDRepCert(cardano_update_drep_cert_t* value) noexcept diff --git a/lib/src/Certificates/VoteDelegationCert.cpp b/lib/src/Certificates/VoteDelegationCert.cpp index 06541ad1..3fa11d84 100644 --- a/lib/src/Certificates/VoteDelegationCert.cpp +++ b/lib/src/Certificates/VoteDelegationCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ VoteDelegationCert::VoteDelegationCert(const Credential& credential, const DRep& const Credential copy(credential); const DRep drepCopy(drep); cardano_vote_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_vote_delegation_cert_new(copy.checked(), drepCopy.checked(), &value); + const cardano_error_t status = cardano_vote_delegation_cert_new(checkedNativeHandle(copy), checkedNativeHandle(drepCopy), &value); CardanoObject owner(value); checkCardanoError(status, "VoteDelegationCert"); @@ -90,7 +92,7 @@ VoteDelegationCert::credential() const throw std::logic_error("Vote delegation certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -98,7 +100,7 @@ void VoteDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_vote_delegation_cert_set_credential(checked(), copy.checked()), "VoteDelegationCert setCredential"); + checkCardanoError(cardano_vote_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "VoteDelegationCert setCredential"); } DRep @@ -110,7 +112,7 @@ VoteDelegationCert::drep() const throw std::logic_error("Vote delegation certificate has no DRep"); } - const DRep result(value); + const DRep result = DRep::adopt(value); return DRep(result); } @@ -118,7 +120,7 @@ void VoteDelegationCert::setDRep(const DRep& value) { const DRep copy(value); - checkCardanoError(cardano_vote_delegation_cert_set_drep(checked(), copy.checked()), "VoteDelegationCert setDRep"); + checkCardanoError(cardano_vote_delegation_cert_set_drep(checked(), checkedNativeHandle(copy)), "VoteDelegationCert setDRep"); } std::vector @@ -175,6 +177,35 @@ VoteDelegationCert::operator!=(const VoteDelegationCert& other) const return !(*this == other); } +VoteDelegationCert +VoteDelegationCert::adopt(cardano_vote_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null VoteDelegationCert"); + } + + return VoteDelegationCert(value); +} + +cardano_vote_delegation_cert_t* +VoteDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_vote_delegation_cert_t* +VoteDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_vote_delegation_cert_t* +VoteDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ VoteDelegationCert::VoteDelegationCert(cardano_vote_delegation_cert_t* value) noexcept diff --git a/lib/src/Certificates/VoteRegistrationDelegationCert.cpp b/lib/src/Certificates/VoteRegistrationDelegationCert.cpp index 6decd185..29e21ad9 100644 --- a/lib/src/Certificates/VoteRegistrationDelegationCert.cpp +++ b/lib/src/Certificates/VoteRegistrationDelegationCert.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ VoteRegistrationDelegationCert::VoteRegistrationDelegationCert(const Credential& const Credential copy(credential); const DRep drepCopy(drep); cardano_vote_registration_delegation_cert_t* value = nullptr; - const cardano_error_t status = cardano_vote_registration_delegation_cert_new(copy.checked(), deposit, drepCopy.checked(), &value); + const cardano_error_t status = cardano_vote_registration_delegation_cert_new(checkedNativeHandle(copy), deposit, checkedNativeHandle(drepCopy), &value); CardanoObject owner(value); checkCardanoError(status, "VoteRegistrationDelegationCert"); @@ -90,7 +92,7 @@ VoteRegistrationDelegationCert::credential() const throw std::logic_error("Vote delegation certificate has no credential"); } - const Credential result(value); + const Credential result = Credential::adopt(value); return Credential(result); } @@ -98,7 +100,7 @@ void VoteRegistrationDelegationCert::setCredential(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_vote_registration_delegation_cert_set_credential(checked(), copy.checked()), "VoteRegistrationDelegationCert setCredential"); + checkCardanoError(cardano_vote_registration_delegation_cert_set_credential(checked(), checkedNativeHandle(copy)), "VoteRegistrationDelegationCert setCredential"); } DRep @@ -110,7 +112,7 @@ VoteRegistrationDelegationCert::drep() const throw std::logic_error("Vote delegation certificate has no DRep"); } - const DRep result(value); + const DRep result = DRep::adopt(value); return DRep(result); } @@ -118,7 +120,7 @@ void VoteRegistrationDelegationCert::setDRep(const DRep& value) { const DRep copy(value); - checkCardanoError(cardano_vote_registration_delegation_cert_set_drep(checked(), copy.checked()), "VoteRegistrationDelegationCert setDRep"); + checkCardanoError(cardano_vote_registration_delegation_cert_set_drep(checked(), checkedNativeHandle(copy)), "VoteRegistrationDelegationCert setDRep"); } std::uint64_t @@ -187,6 +189,35 @@ VoteRegistrationDelegationCert::operator!=(const VoteRegistrationDelegationCert& return !(*this == other); } +VoteRegistrationDelegationCert +VoteRegistrationDelegationCert::adopt(cardano_vote_registration_delegation_cert_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null VoteRegistrationDelegationCert"); + } + + return VoteRegistrationDelegationCert(value); +} + +cardano_vote_registration_delegation_cert_t* +VoteRegistrationDelegationCert::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_vote_registration_delegation_cert_t* +VoteRegistrationDelegationCert::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_vote_registration_delegation_cert_t* +VoteRegistrationDelegationCert::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ VoteRegistrationDelegationCert::VoteRegistrationDelegationCert(cardano_vote_registration_delegation_cert_t* value) noexcept diff --git a/lib/src/Common/Anchor.cpp b/lib/src/Common/Anchor.cpp index 5ed7a553..bc8287b4 100644 --- a/lib/src/Common/Anchor.cpp +++ b/lib/src/Common/Anchor.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -185,6 +187,35 @@ Anchor::operator!=(const Anchor& other) const return !(*this == other); } +Anchor +Anchor::adopt(cardano_anchor_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Anchor"); + } + + return Anchor(value); +} + +cardano_anchor_t* +Anchor::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_anchor_t* +Anchor::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_anchor_t* +Anchor::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Anchor::Anchor(cardano_anchor_t* value) noexcept diff --git a/lib/src/Common/BigInt.cpp b/lib/src/Common/BigInt.cpp index d317ec99..b9a4e9c8 100644 --- a/lib/src/Common/BigInt.cpp +++ b/lib/src/Common/BigInt.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* INTERNAL IMPLEMENTATION ***************************************************/ namespace Cometa @@ -742,6 +744,35 @@ BigInt::operator>=(const BigInt& other) const return cardano_bigint_compare(checked(), other.checked()) >= 0; } +BigInt +BigInt::adopt(cardano_bigint_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null BigInt"); + } + + return BigInt(*value); +} + +cardano_bigint_t* +BigInt::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_bigint_t* +BigInt::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_bigint_t* +BigInt::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ BigInt::BigInt(cardano_bigint_t& value) noexcept diff --git a/lib/src/Common/Credential.cpp b/lib/src/Common/Credential.cpp index 47516d68..81a86694 100644 --- a/lib/src/Common/Credential.cpp +++ b/lib/src/Common/Credential.cpp @@ -29,6 +29,8 @@ #include +#include + /* INTERNAL IMPLEMENTATION ***************************************************/ namespace Cometa @@ -229,6 +231,35 @@ Credential::operator<(const Credential& other) const return cardano_credential_compare(checked(), other.checked()) < 0; } +Credential +Credential::adopt(cardano_credential_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Credential"); + } + + return Credential(value); +} + +cardano_credential_t* +Credential::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_credential_t* +Credential::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_credential_t* +Credential::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Credential::Credential(cardano_credential_t* value) noexcept diff --git a/lib/src/Common/CredentialSet.cpp b/lib/src/Common/CredentialSet.cpp index cea61ec1..c3dccca5 100644 --- a/lib/src/Common/CredentialSet.cpp +++ b/lib/src/Common/CredentialSet.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -133,7 +135,7 @@ CredentialSet::contains(const Credential& value) const checkCardanoError(status, "CredentialSet contains"); - if (cardano_credential_equals(owner.get(), value.checked())) + if (cardano_credential_equals(owner.get(), checkedNativeHandle(value))) { return true; } @@ -155,7 +157,7 @@ CredentialSet::at(std::size_t index) const CardanoObject owner(element); checkCardanoError(status, "CredentialSet at"); - const Credential value(owner.release()); + const Credential value = Credential::adopt(owner.release()); return Credential(value); } @@ -429,6 +431,41 @@ CredentialSet::erase(const value_type& value) return 1; } +CredentialSet +CredentialSet::adopt(cardano_credential_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CredentialSet"); + } + + return CredentialSet(value); +} + +cardano_credential_set_t* +CredentialSet::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_credential_set_t* +CredentialSet::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_credential_set_t* +CredentialSet::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ CredentialSet::CredentialSet(cardano_credential_set_t* value) noexcept @@ -491,7 +528,7 @@ CredentialSet::insertValue(const Credential& value) const Credential copy(value); - checkCardanoError(cardano_credential_set_add(checked(), copy.checked()), "CredentialSet insert"); + checkCardanoError(cardano_credential_set_add(checked(), checkedNativeHandle(copy)), "CredentialSet insert"); invalidateElements(); return true; diff --git a/lib/src/Common/DRep.cpp b/lib/src/Common/DRep.cpp index 88e5024c..b983e851 100644 --- a/lib/src/Common/DRep.cpp +++ b/lib/src/Common/DRep.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ DRep::DRep(DRepType type, std::optional credential) validate(type, credential); cardano_drep_t* value = nullptr; - const cardano_error_t status = cardano_drep_new(static_cast(type), credential ? credential->checked() : nullptr, &value); + const cardano_error_t status = cardano_drep_new(static_cast(type), credential ? checkedNativeHandle(*credential) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "DRep"); @@ -127,7 +129,7 @@ DRep::credential() const CardanoObject owner(value); checkCardanoError(status, "DRep credential"); - Credential copied(owner.release()); + Credential copied = Credential::adopt(owner.release()); return Credential(copied); } @@ -137,7 +139,7 @@ DRep::setCredential(const Credential& value) validate(type(), value); Credential copy(value); - checkCardanoError(cardano_drep_set_credential(checked(), copy.checked()), "DRep setCredential"); + checkCardanoError(cardano_drep_set_credential(checked(), checkedNativeHandle(copy)), "DRep setCredential"); } void @@ -217,6 +219,35 @@ DRep::operator!=(const DRep& other) const return !(*this == other); } +DRep +DRep::adopt(cardano_drep_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null DRep"); + } + + return DRep(value); +} + +cardano_drep_t* +DRep::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_drep_t* +DRep::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_drep_t* +DRep::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ DRep::DRep(cardano_drep_t* value) noexcept diff --git a/lib/src/Common/Datum.cpp b/lib/src/Common/Datum.cpp index 8c24317b..9689f103 100644 --- a/lib/src/Common/Datum.cpp +++ b/lib/src/Common/Datum.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -59,7 +61,7 @@ Datum::Datum(const PlutusData& data) PlutusData copy(data); cardano_datum_t* value = nullptr; - const cardano_error_t result = cardano_datum_new_inline_data(copy.checked(), &value); + const cardano_error_t result = cardano_datum_new_inline_data(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -121,7 +123,7 @@ Datum::inlineData() const return std::nullopt; } - const PlutusData data(*cardano_datum_get_inline_data(checked())); + const PlutusData data = PlutusData::adopt(cardano_datum_get_inline_data(checked())); return PlutusData(data); } @@ -207,6 +209,35 @@ Datum::operator!=(const Datum& other) const return !(*this == other); } +Datum +Datum::adopt(cardano_datum_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Datum"); + } + + return Datum(*value); +} + +cardano_datum_t* +Datum::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_datum_t* +Datum::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_datum_t* +Datum::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Datum::Datum(cardano_datum_t& value) noexcept diff --git a/lib/src/Common/ExUnits.cpp b/lib/src/Common/ExUnits.cpp index 8b7b062e..b75dd690 100644 --- a/lib/src/Common/ExUnits.cpp +++ b/lib/src/Common/ExUnits.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -160,6 +162,35 @@ ExUnits::operator!=(const ExUnits& other) const return !(*this == other); } +ExUnits +ExUnits::adopt(cardano_ex_units_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ExUnits"); + } + + return ExUnits(value); +} + +cardano_ex_units_t* +ExUnits::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ex_units_t* +ExUnits::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ex_units_t* +ExUnits::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ExUnits::ExUnits(cardano_ex_units_t* value) noexcept diff --git a/lib/src/Common/GovernanceActionId.cpp b/lib/src/Common/GovernanceActionId.cpp index 2e762cb6..3114d3a9 100644 --- a/lib/src/Common/GovernanceActionId.cpp +++ b/lib/src/Common/GovernanceActionId.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -205,6 +207,35 @@ GovernanceActionId::operator!=(const GovernanceActionId& other) const return !(*this == other); } +GovernanceActionId +GovernanceActionId::adopt(cardano_governance_action_id_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null GovernanceActionId"); + } + + return GovernanceActionId(value); +} + +cardano_governance_action_id_t* +GovernanceActionId::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_governance_action_id_t* +GovernanceActionId::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_governance_action_id_t* +GovernanceActionId::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ GovernanceActionId::GovernanceActionId(cardano_governance_action_id_t* value) noexcept diff --git a/lib/src/Common/ProtocolVersion.cpp b/lib/src/Common/ProtocolVersion.cpp index 63327597..73fcd2f4 100644 --- a/lib/src/Common/ProtocolVersion.cpp +++ b/lib/src/Common/ProtocolVersion.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -172,6 +174,35 @@ ProtocolVersion::operator!=(const ProtocolVersion& other) const return !(*this == other); } +ProtocolVersion +ProtocolVersion::adopt(cardano_protocol_version_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProtocolVersion"); + } + + return ProtocolVersion(value); +} + +cardano_protocol_version_t* +ProtocolVersion::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_protocol_version_t* +ProtocolVersion::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_protocol_version_t* +ProtocolVersion::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ProtocolVersion::ProtocolVersion(cardano_protocol_version_t* value) noexcept diff --git a/lib/src/Common/UnitInterval.cpp b/lib/src/Common/UnitInterval.cpp index 55ae8be0..605cce29 100644 --- a/lib/src/Common/UnitInterval.cpp +++ b/lib/src/Common/UnitInterval.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -212,6 +214,35 @@ UnitInterval::operator!=(const UnitInterval& other) const return !(*this == other); } +UnitInterval +UnitInterval::adopt(cardano_unit_interval_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null UnitInterval"); + } + + return UnitInterval(value); +} + +cardano_unit_interval_t* +UnitInterval::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_unit_interval_t* +UnitInterval::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_unit_interval_t* +UnitInterval::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ UnitInterval::UnitInterval(cardano_unit_interval_t* value) noexcept diff --git a/lib/src/Common/Utxo.cpp b/lib/src/Common/Utxo.cpp index 70d51544..fd952398 100644 --- a/lib/src/Common/Utxo.cpp +++ b/lib/src/Common/Utxo.cpp @@ -26,12 +26,15 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -43,7 +46,7 @@ Utxo::Utxo(const TransactionInput& input, const TransactionOutput& output) TransactionOutput outputCopy(output); cardano_utxo_t* value = nullptr; - const cardano_error_t result = cardano_utxo_new(inputCopy.checked(), outputCopy.checked(), &value); + const cardano_error_t result = cardano_utxo_new(checkedNativeHandle(inputCopy), checkedNativeHandle(outputCopy), &value); CardanoObject owner(value); @@ -80,7 +83,7 @@ Utxo::fromCbor(const std::vector& cbor) { Utxo value(*decodeCbor(cbor, cardano_utxo_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -97,7 +100,7 @@ Utxo::input() const cardano_transaction_input_t* value = cardano_utxo_get_input(checked()); CardanoObject owner(value); - const TransactionInput component(*owner.release()); + const TransactionInput component = TransactionInput::adopt(owner.release()); return TransactionInput(component); } @@ -107,7 +110,7 @@ Utxo::setInput(const TransactionInput& value) { TransactionInput copy(value); - checkCardanoError(cardano_utxo_set_input(checked(), copy.checked()), "Utxo setInput"); + checkCardanoError(cardano_utxo_set_input(checked(), checkedNativeHandle(copy)), "Utxo setInput"); } TransactionOutput @@ -116,7 +119,7 @@ Utxo::output() const cardano_transaction_output_t* value = cardano_utxo_get_output(checked()); CardanoObject owner(value); - const TransactionOutput component(*owner.release()); + const TransactionOutput component = TransactionOutput::adopt(owner.release()); return TransactionOutput(component); } @@ -126,7 +129,7 @@ Utxo::setOutput(const TransactionOutput& value) { TransactionOutput copy(value); - checkCardanoError(cardano_utxo_set_output(checked(), copy.checked()), "Utxo setOutput"); + checkCardanoError(cardano_utxo_set_output(checked(), checkedNativeHandle(copy)), "Utxo setOutput"); } std::vector @@ -184,6 +187,35 @@ Utxo::operator!=(const Utxo& other) const return !(*this == other); } +Utxo +Utxo::adopt(cardano_utxo_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Utxo"); + } + + return Utxo(*value); +} + +cardano_utxo_t* +Utxo::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_utxo_t* +Utxo::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_utxo_t* +Utxo::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Utxo::Utxo(cardano_utxo_t& value) noexcept @@ -203,10 +235,10 @@ Utxo::checked() const } void -Utxo::validate() const +validateValue(const Utxo& value) { - input().validate(); - output().validate(); + validateValue(value.input()); + validateValue(value.output()); } /* FUNCTIONS IMPLEMENTATION **************************************************/ diff --git a/lib/src/Common/WithdrawalMap.cpp b/lib/src/Common/WithdrawalMap.cpp index 658db89e..308ac247 100644 --- a/lib/src/Common/WithdrawalMap.cpp +++ b/lib/src/Common/WithdrawalMap.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -118,7 +120,7 @@ std::optional WithdrawalMap::get(const RewardAddress& key) const { std::uint64_t amount = 0U; - const cardano_error_t result = cardano_withdrawal_map_get(checked(), key.checked(), &amount); + const cardano_error_t result = cardano_withdrawal_map_get(checked(), checkedNativeHandle(key), &amount); if (result == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -141,7 +143,7 @@ WithdrawalMap::set(const RewardAddress& key, std::uint64_t amount) for (const std::pair& entry: current) { const std::uint64_t quantity = entry.first == key ? amount : entry.second; - checkCardanoError(cardano_withdrawal_map_insert(replacement.checked(), entry.first.checked(), quantity), "WithdrawalMap replacement"); + checkCardanoError(cardano_withdrawal_map_insert(replacement.checked(), checkedNativeHandle(entry.first), quantity), "WithdrawalMap replacement"); } swap(replacement); @@ -150,7 +152,7 @@ WithdrawalMap::set(const RewardAddress& key, std::uint64_t amount) RewardAddress copy(key); - checkCardanoError(cardano_withdrawal_map_insert(checked(), copy.checked(), amount), "WithdrawalMap set"); + checkCardanoError(cardano_withdrawal_map_insert(checked(), checkedNativeHandle(copy), amount), "WithdrawalMap set"); invalidateElements(); } @@ -177,7 +179,7 @@ WithdrawalMap::entryAt(std::size_t index) const checkCardanoError(result, "WithdrawalMap entryAt"); - const RewardAddress address(*owner.release()); + const RewardAddress address = RewardAddress::adopt(owner.release()); return std::make_pair(RewardAddress(address), amount); } @@ -502,6 +504,60 @@ WithdrawalMap::clear() m_mutableAccess = true; } +WithdrawalMap +WithdrawalMap::adopt(cardano_withdrawal_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null WithdrawalMap"); + } + + return WithdrawalMap(*value); +} + +cardano_withdrawal_map_t* +WithdrawalMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_withdrawal_map_t* +WithdrawalMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_withdrawal_map_t* +WithdrawalMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ WithdrawalMap::WithdrawalMap(cardano_withdrawal_map_t& value) noexcept diff --git a/lib/src/Crypto/Bip32PrivateKey.cpp b/lib/src/Crypto/Bip32PrivateKey.cpp index ff8160dc..2a253339 100644 --- a/lib/src/Crypto/Bip32PrivateKey.cpp +++ b/lib/src/Crypto/Bip32PrivateKey.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -149,7 +151,7 @@ Bip32PrivateKey::toEd25519() const checkCardanoError(result, "Bip32PrivateKey toEd25519"); - return Ed25519PrivateKey(*owner.release()); + return Ed25519PrivateKey::adopt(owner.release()); } Bip32PublicKey @@ -162,7 +164,7 @@ Bip32PrivateKey::publicKey() const checkCardanoError(result, "Bip32PrivateKey publicKey"); - return Bip32PublicKey(*owner.release()); + return Bip32PublicKey::adopt(owner.release()); } void @@ -196,6 +198,35 @@ Bip32PrivateKey::operator=(Bip32PrivateKey&& other) noexcept return *this; } +Bip32PrivateKey +Bip32PrivateKey::adopt(cardano_bip32_private_key_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Bip32PrivateKey"); + } + + return Bip32PrivateKey(*value); +} + +cardano_bip32_private_key_t* +Bip32PrivateKey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_bip32_private_key_t* +Bip32PrivateKey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_bip32_private_key_t* +Bip32PrivateKey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Bip32PrivateKey::Bip32PrivateKey(cardano_bip32_private_key_t& value) noexcept diff --git a/lib/src/Crypto/Bip32PublicKey.cpp b/lib/src/Crypto/Bip32PublicKey.cpp index 627740da..9043d617 100644 --- a/lib/src/Crypto/Bip32PublicKey.cpp +++ b/lib/src/Crypto/Bip32PublicKey.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -118,7 +120,7 @@ Bip32PublicKey::hash() const checkCardanoError(result, "Bip32PublicKey hash"); - return Blake2bHash(owner.release()); + return Blake2bHash::adopt(owner.release()); } Bip32PublicKey @@ -149,7 +151,7 @@ Bip32PublicKey::toEd25519() const checkCardanoError(result, "Bip32PublicKey toEd25519"); - return Ed25519PublicKey(*owner.release()); + return Ed25519PublicKey::adopt(owner.release()); } bool @@ -195,6 +197,35 @@ Bip32PublicKey::operator=(Bip32PublicKey&& other) noexcept return *this; } +Bip32PublicKey +Bip32PublicKey::adopt(cardano_bip32_public_key_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Bip32PublicKey"); + } + + return Bip32PublicKey(*value); +} + +cardano_bip32_public_key_t* +Bip32PublicKey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_bip32_public_key_t* +Bip32PublicKey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_bip32_public_key_t* +Bip32PublicKey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Bip32PublicKey::Bip32PublicKey(cardano_bip32_public_key_t& value) noexcept diff --git a/lib/src/Crypto/Blake2bHash.cpp b/lib/src/Crypto/Blake2bHash.cpp index 864b1cb1..c50d626c 100644 --- a/lib/src/Crypto/Blake2bHash.cpp +++ b/lib/src/Crypto/Blake2bHash.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -214,6 +216,35 @@ Blake2bHash::operator<(const Blake2bHash& other) const return cardano_blake2b_hash_compare(checked(), other.checked()) < 0; } +Blake2bHash +Blake2bHash::adopt(cardano_blake2b_hash_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Blake2bHash"); + } + + return Blake2bHash(value); +} + +cardano_blake2b_hash_t* +Blake2bHash::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_blake2b_hash_t* +Blake2bHash::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_blake2b_hash_t* +Blake2bHash::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Blake2bHash::Blake2bHash(cardano_blake2b_hash_t* value) noexcept diff --git a/lib/src/Crypto/Blake2bHashSet.cpp b/lib/src/Crypto/Blake2bHashSet.cpp index 6d36ae98..13974a1c 100644 --- a/lib/src/Crypto/Blake2bHashSet.cpp +++ b/lib/src/Crypto/Blake2bHashSet.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -133,7 +135,7 @@ Blake2bHashSet::contains(const Blake2bHash& value) const checkCardanoError(status, "Blake2bHashSet contains"); - if (cardano_blake2b_hash_equals(owner.get(), value.checked())) + if (cardano_blake2b_hash_equals(owner.get(), checkedNativeHandle(value))) { return true; } @@ -155,7 +157,7 @@ Blake2bHashSet::at(std::size_t index) const CardanoObject owner(element); checkCardanoError(status, "Blake2bHashSet at"); - const Blake2bHash value(owner.release()); + const Blake2bHash value = Blake2bHash::adopt(owner.release()); return Blake2bHash(value); } @@ -429,6 +431,41 @@ Blake2bHashSet::erase(const value_type& value) return 1; } +Blake2bHashSet +Blake2bHashSet::adopt(cardano_blake2b_hash_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Blake2bHashSet"); + } + + return Blake2bHashSet(value); +} + +cardano_blake2b_hash_set_t* +Blake2bHashSet::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_blake2b_hash_set_t* +Blake2bHashSet::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_blake2b_hash_set_t* +Blake2bHashSet::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Blake2bHashSet::Blake2bHashSet(cardano_blake2b_hash_set_t* value) noexcept @@ -491,7 +528,7 @@ Blake2bHashSet::insertValue(const Blake2bHash& value) const Blake2bHash copy(value); - checkCardanoError(cardano_blake2b_hash_set_add(checked(), copy.checked()), "Blake2bHashSet insert"); + checkCardanoError(cardano_blake2b_hash_set_add(checked(), checkedNativeHandle(copy)), "Blake2bHashSet insert"); invalidateElements(); return true; diff --git a/lib/src/Crypto/Ed25519PrivateKey.cpp b/lib/src/Crypto/Ed25519PrivateKey.cpp index d3ff1474..dedbff36 100644 --- a/lib/src/Crypto/Ed25519PrivateKey.cpp +++ b/lib/src/Crypto/Ed25519PrivateKey.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -152,7 +154,7 @@ Ed25519PrivateKey::sign(const std::vector& message) const checkCardanoError(result, "Ed25519PrivateKey sign"); - return Ed25519Signature(*owner.release()); + return Ed25519Signature::adopt(owner.release()); } Ed25519PublicKey @@ -165,7 +167,7 @@ Ed25519PrivateKey::publicKey() const checkCardanoError(result, "Ed25519PrivateKey publicKey"); - return Ed25519PublicKey(*owner.release()); + return Ed25519PublicKey::adopt(owner.release()); } void @@ -199,6 +201,35 @@ Ed25519PrivateKey::operator=(Ed25519PrivateKey&& other) noexcept return *this; } +Ed25519PrivateKey +Ed25519PrivateKey::adopt(cardano_ed25519_private_key_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Ed25519PrivateKey"); + } + + return Ed25519PrivateKey(*value); +} + +cardano_ed25519_private_key_t* +Ed25519PrivateKey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ed25519_private_key_t* +Ed25519PrivateKey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ed25519_private_key_t* +Ed25519PrivateKey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Ed25519PrivateKey::Ed25519PrivateKey(cardano_ed25519_private_key_t& value) noexcept diff --git a/lib/src/Crypto/Ed25519PublicKey.cpp b/lib/src/Crypto/Ed25519PublicKey.cpp index 33b34cfa..6e2971af 100644 --- a/lib/src/Crypto/Ed25519PublicKey.cpp +++ b/lib/src/Crypto/Ed25519PublicKey.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -111,7 +113,7 @@ Ed25519PublicKey::toHex() const bool Ed25519PublicKey::verify(const Ed25519Signature& signature, const std::vector& message) const { - return cardano_ed25519_public_verify(checked(), signature.checked(), byteData(message), message.size()); + return cardano_ed25519_public_verify(checked(), checkedNativeHandle(signature), byteData(message), message.size()); } Blake2bHash @@ -124,7 +126,7 @@ Ed25519PublicKey::hash() const checkCardanoError(result, "Ed25519PublicKey hash"); - return Blake2bHash(owner.release()); + return Blake2bHash::adopt(owner.release()); } bool @@ -170,6 +172,35 @@ Ed25519PublicKey::operator=(Ed25519PublicKey&& other) noexcept return *this; } +Ed25519PublicKey +Ed25519PublicKey::adopt(cardano_ed25519_public_key_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Ed25519PublicKey"); + } + + return Ed25519PublicKey(*value); +} + +cardano_ed25519_public_key_t* +Ed25519PublicKey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ed25519_public_key_t* +Ed25519PublicKey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ed25519_public_key_t* +Ed25519PublicKey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Ed25519PublicKey::Ed25519PublicKey(cardano_ed25519_public_key_t& value) noexcept diff --git a/lib/src/Crypto/Ed25519Signature.cpp b/lib/src/Crypto/Ed25519Signature.cpp index 14a40cfe..d4fdb95c 100644 --- a/lib/src/Crypto/Ed25519Signature.cpp +++ b/lib/src/Crypto/Ed25519Signature.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -151,6 +153,35 @@ Ed25519Signature::operator=(Ed25519Signature&& other) noexcept return *this; } +Ed25519Signature +Ed25519Signature::adopt(cardano_ed25519_signature_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Ed25519Signature"); + } + + return Ed25519Signature(*value); +} + +cardano_ed25519_signature_t* +Ed25519Signature::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ed25519_signature_t* +Ed25519Signature::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ed25519_signature_t* +Ed25519Signature::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Ed25519Signature::Ed25519Signature(cardano_ed25519_signature_t& value) noexcept diff --git a/lib/src/Json/JsonValue.cpp b/lib/src/Json/JsonValue.cpp index c3461922..586aa19e 100644 --- a/lib/src/Json/JsonValue.cpp +++ b/lib/src/Json/JsonValue.cpp @@ -34,6 +34,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -266,6 +268,35 @@ JsonValue::operator=(JsonValue&& other) noexcept return *this; } +JsonValue +JsonValue::adopt(cardano_json_object_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null JsonValue"); + } + + return JsonValue(*value); +} + +cardano_json_object_t* +JsonValue::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_json_object_t* +JsonValue::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_json_object_t* +JsonValue::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ cardano_json_object_t* diff --git a/lib/src/Json/JsonWriter.cpp b/lib/src/Json/JsonWriter.cpp index b972f2de..c7e4d461 100644 --- a/lib/src/Json/JsonWriter.cpp +++ b/lib/src/Json/JsonWriter.cpp @@ -34,6 +34,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -201,7 +203,7 @@ JsonWriter::writeRaw(std::string_view json) void JsonWriter::writeValue(const JsonValue& value) { - cardano_json_writer_write_object(checked(), value.checked()); + cardano_json_writer_write_object(checked(), checkedNativeHandle(value)); checkWrite(); } @@ -217,7 +219,7 @@ JsonWriter::writeBigInt(const BigInt& value) void JsonWriter::writeBigIntAsString(const BigInt& value) { - cardano_json_writer_write_bigint(checked(), value.checked()); + cardano_json_writer_write_bigint(checked(), checkedNativeHandle(value)); checkWrite(); } @@ -307,8 +309,48 @@ JsonWriter::operator=(JsonWriter&& other) noexcept return *this; } +JsonWriter +JsonWriter::adopt(cardano_json_writer_t* value, JsonFormat format) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null JsonWriter"); + } + + if (format != JsonFormat::Compact && format != JsonFormat::Pretty) + { + throw std::invalid_argument("Unknown JSON format"); + } + + return JsonWriter(value, format); +} + +cardano_json_writer_t* +JsonWriter::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_json_writer_t* +JsonWriter::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_json_writer_t* +JsonWriter::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ +JsonWriter::JsonWriter(cardano_json_writer_t* value, JsonFormat format) noexcept +: m_value(value) +, m_format(format) +{ +} + cardano_json_writer_t* JsonWriter::checked() const { diff --git a/lib/src/KeyHandlers/SecureKeyHandler.cpp b/lib/src/KeyHandlers/SecureKeyHandler.cpp index 8c7c77b2..c4476574 100644 --- a/lib/src/KeyHandlers/SecureKeyHandler.cpp +++ b/lib/src/KeyHandlers/SecureKeyHandler.cpp @@ -832,6 +832,18 @@ SecureKeyHandler::operator=(SecureKeyHandler&& other) noexcept return *this; } +cardano_secure_key_handler_t* +SecureKeyHandler::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_secure_key_handler_t* +SecureKeyHandler::nativeHandle() const noexcept +{ + return m_value; +} + /* PRIVATE FUNCTIONS *********************************************************/ SecureKeyHandler::SecureKeyHandler(cardano_secure_key_handler_t* value, SecureKeyHandlerType type, std::shared_ptr provider) noexcept diff --git a/lib/src/PlutusData/ConstrPlutusData.cpp b/lib/src/PlutusData/ConstrPlutusData.cpp index 256159f9..c07bc95a 100644 --- a/lib/src/PlutusData/ConstrPlutusData.cpp +++ b/lib/src/PlutusData/ConstrPlutusData.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ ConstrPlutusData::ConstrPlutusData(std::uint64_t alternative, const PlutusList& PlutusList copy(fields); cardano_constr_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_constr_plutus_data_new(alternative, copy.checked(), &value); + const cardano_error_t result = cardano_constr_plutus_data_new(alternative, checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -111,7 +113,7 @@ ConstrPlutusData::fields() const checkCardanoError(result, "ConstrPlutusData fields"); - const PlutusList data(*owner.release()); + const PlutusList data = PlutusList::adopt(owner.release()); return PlutusList(data); } @@ -121,7 +123,7 @@ ConstrPlutusData::setFields(const PlutusList& fields) { PlutusList copy(fields); - checkCardanoError(cardano_constr_plutus_data_set_data(checked(), copy.checked()), "ConstrPlutusData setFields"); + checkCardanoError(cardano_constr_plutus_data_set_data(checked(), checkedNativeHandle(copy)), "ConstrPlutusData setFields"); normalizeEncoding(); } @@ -186,6 +188,35 @@ ConstrPlutusData::operator!=(const ConstrPlutusData& other) const return !(*this == other); } +ConstrPlutusData +ConstrPlutusData::adopt(cardano_constr_plutus_data_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ConstrPlutusData"); + } + + return ConstrPlutusData(*value); +} + +cardano_constr_plutus_data_t* +ConstrPlutusData::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_constr_plutus_data_t* +ConstrPlutusData::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_constr_plutus_data_t* +ConstrPlutusData::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ConstrPlutusData::ConstrPlutusData(cardano_constr_plutus_data_t& value) noexcept diff --git a/lib/src/PlutusData/PlutusData.cpp b/lib/src/PlutusData/PlutusData.cpp index 64498a17..5948ad06 100644 --- a/lib/src/PlutusData/PlutusData.cpp +++ b/lib/src/PlutusData/PlutusData.cpp @@ -58,7 +58,7 @@ PlutusData::PlutusData(const BigInt& integer) : m_value(nullptr) { cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_integer(integer.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_integer(checkedNativeHandle(integer), &value); CardanoObject owner(value); @@ -86,7 +86,7 @@ PlutusData::PlutusData(const PlutusList& data) PlutusList copy(data); cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_list(copy.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_list(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -99,7 +99,7 @@ PlutusData::PlutusData(PlutusList&& data) : m_value(nullptr) { cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_list(data.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_list(checkedNativeHandle(data), &value); CardanoObject owner(value); @@ -116,7 +116,7 @@ PlutusData::PlutusData(const PlutusMap& data) PlutusMap copy(data); cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_map(copy.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_map(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -129,7 +129,7 @@ PlutusData::PlutusData(PlutusMap&& data) : m_value(nullptr) { cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_map(data.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_map(checkedNativeHandle(data), &value); CardanoObject owner(value); @@ -146,7 +146,7 @@ PlutusData::PlutusData(const ConstrPlutusData& data) ConstrPlutusData copy(data); cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_constr(copy.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_constr(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -159,7 +159,7 @@ PlutusData::PlutusData(ConstrPlutusData&& data) : m_value(nullptr) { cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_data_new_constr(data.checked(), &value); + const cardano_error_t result = cardano_plutus_data_new_constr(checkedNativeHandle(data), &value); CardanoObject owner(value); @@ -244,7 +244,7 @@ PlutusData::asList() const checkCardanoError(result, "PlutusData asList"); - const PlutusList data(*owner.release()); + const PlutusList data = PlutusList::adopt(owner.release()); return PlutusList(data); } @@ -259,7 +259,7 @@ PlutusData::asMap() const checkCardanoError(result, "PlutusData asMap"); - const PlutusMap data(*owner.release()); + const PlutusMap data = PlutusMap::adopt(owner.release()); return PlutusMap(data); } @@ -274,7 +274,7 @@ PlutusData::asConstructor() const checkCardanoError(result, "PlutusData asConstr"); - const ConstrPlutusData data(*owner.release()); + const ConstrPlutusData data = ConstrPlutusData::adopt(owner.release()); return ConstrPlutusData(data); } @@ -289,7 +289,7 @@ PlutusData::asInteger() const checkCardanoError(result, "PlutusData asInteger"); - return BigInt(*owner.release()); + return BigInt::adopt(owner.release()); } std::vector @@ -374,6 +374,35 @@ PlutusData::operator!=(const PlutusData& other) const return !(*this == other); } +PlutusData +PlutusData::adopt(cardano_plutus_data_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusData"); + } + + return PlutusData(*value); +} + +cardano_plutus_data_t* +PlutusData::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_plutus_data_t* +PlutusData::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_plutus_data_t* +PlutusData::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusData::PlutusData(cardano_plutus_data_t& value) noexcept diff --git a/lib/src/PlutusData/PlutusList.cpp b/lib/src/PlutusData/PlutusList.cpp index ed77cf3c..b3b072b7 100644 --- a/lib/src/PlutusData/PlutusList.cpp +++ b/lib/src/PlutusData/PlutusList.cpp @@ -34,6 +34,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -118,7 +120,7 @@ PlutusList::pushBack(const PlutusData& data) PlutusData copy(data); - checkCardanoError(cardano_plutus_list_add(checked(), copy.checked()), "PlutusList pushBack"); + checkCardanoError(cardano_plutus_list_add(checked(), checkedNativeHandle(copy)), "PlutusList pushBack"); normalizeEncoding(); } @@ -474,6 +476,60 @@ PlutusList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusList +PlutusList::adopt(cardano_plutus_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusList"); + } + + return PlutusList(*value); +} + +cardano_plutus_list_t* +PlutusList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_list_t* +PlutusList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_list_t* +PlutusList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusList::PlutusList(cardano_plutus_list_t& value) noexcept @@ -567,7 +623,7 @@ PlutusList::copyElement(std::size_t index) const checkCardanoError(result, "PlutusList at"); - const PlutusData data(*owner.release()); + const PlutusData data = PlutusData::adopt(owner.release()); return PlutusData(data); } diff --git a/lib/src/PlutusData/PlutusMap.cpp b/lib/src/PlutusData/PlutusMap.cpp index eadf8acf..eb82e162 100644 --- a/lib/src/PlutusData/PlutusMap.cpp +++ b/lib/src/PlutusData/PlutusMap.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -109,7 +111,7 @@ std::optional PlutusMap::get(const PlutusData& key) const { cardano_plutus_data_t* value = nullptr; - const cardano_error_t result = cardano_plutus_map_get(checked(), key.checked(), &value); + const cardano_error_t result = cardano_plutus_map_get(checked(), checkedNativeHandle(key), &value); CardanoObject owner(value); @@ -120,7 +122,7 @@ PlutusMap::get(const PlutusData& key) const checkCardanoError(result, "PlutusMap get"); - const PlutusData data(*owner.release()); + const PlutusData data = PlutusData::adopt(owner.release()); return PlutusData(data); } @@ -138,7 +140,7 @@ PlutusMap::insert(const PlutusData& key, const PlutusData& value) PlutusData valueCopy(value); PlutusMap replacement(*this); - checkCardanoError(cardano_plutus_map_insert(replacement.checked(), keyCopy.checked(), valueCopy.checked()), "PlutusMap insert"); + checkCardanoError(cardano_plutus_map_insert(replacement.nativeHandle(), checkedNativeHandle(keyCopy), checkedNativeHandle(valueCopy)), "PlutusMap insert"); replacement.normalizeEncoding(); swap(replacement); } @@ -153,7 +155,7 @@ PlutusMap::keys() const checkCardanoError(result, "PlutusMap keys"); - const PlutusList list(*owner.release()); + const PlutusList list = PlutusList::adopt(owner.release()); return list.values(); } @@ -168,7 +170,7 @@ PlutusMap::values() const checkCardanoError(result, "PlutusMap values"); - const PlutusList list(*owner.release()); + const PlutusList list = PlutusList::adopt(owner.release()); return list.values(); } @@ -539,6 +541,60 @@ PlutusMap::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +PlutusMap +PlutusMap::adopt(cardano_plutus_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusMap"); + } + + return PlutusMap(*value); +} + +cardano_plutus_map_t* +PlutusMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_plutus_map_t* +PlutusMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_plutus_map_t* +PlutusMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusMap::PlutusMap(cardano_plutus_map_t& value) noexcept diff --git a/lib/src/PoolParams/BlsKey.cpp b/lib/src/PoolParams/BlsKey.cpp index 85e86a54..ce989fc8 100644 --- a/lib/src/PoolParams/BlsKey.cpp +++ b/lib/src/PoolParams/BlsKey.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -160,6 +162,35 @@ BlsKey::operator!=(const BlsKey& other) const return !(*this == other); } +BlsKey +BlsKey::adopt(cardano_bls_key_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null BlsKey"); + } + + return BlsKey(*value); +} + +cardano_bls_key_t* +BlsKey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_bls_key_t* +BlsKey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_bls_key_t* +BlsKey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ BlsKey::BlsKey(cardano_bls_key_t& value) noexcept diff --git a/lib/src/PoolParams/Ipv4.cpp b/lib/src/PoolParams/Ipv4.cpp index 915a3448..90cd831b 100644 --- a/lib/src/PoolParams/Ipv4.cpp +++ b/lib/src/PoolParams/Ipv4.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -158,6 +160,35 @@ Ipv4::operator!=(const Ipv4& other) const return !(*this == other); } +Ipv4 +Ipv4::adopt(cardano_ipv4_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Ipv4"); + } + + return Ipv4(*value); +} + +cardano_ipv4_t* +Ipv4::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ipv4_t* +Ipv4::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ipv4_t* +Ipv4::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Ipv4::Ipv4(cardano_ipv4_t& value) noexcept diff --git a/lib/src/PoolParams/Ipv6.cpp b/lib/src/PoolParams/Ipv6.cpp index 6101fa10..eb09df21 100644 --- a/lib/src/PoolParams/Ipv6.cpp +++ b/lib/src/PoolParams/Ipv6.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -158,6 +160,35 @@ Ipv6::operator!=(const Ipv6& other) const return !(*this == other); } +Ipv6 +Ipv6::adopt(cardano_ipv6_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Ipv6"); + } + + return Ipv6(*value); +} + +cardano_ipv6_t* +Ipv6::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ipv6_t* +Ipv6::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ipv6_t* +Ipv6::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Ipv6::Ipv6(cardano_ipv6_t& value) noexcept diff --git a/lib/src/PoolParams/MultiHostNameRelay.cpp b/lib/src/PoolParams/MultiHostNameRelay.cpp index f3d9d816..90922351 100644 --- a/lib/src/PoolParams/MultiHostNameRelay.cpp +++ b/lib/src/PoolParams/MultiHostNameRelay.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -156,6 +158,35 @@ MultiHostNameRelay::operator!=(const MultiHostNameRelay& other) const return !(*this == other); } +MultiHostNameRelay +MultiHostNameRelay::adopt(cardano_multi_host_name_relay_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null MultiHostNameRelay"); + } + + return MultiHostNameRelay(*value); +} + +cardano_multi_host_name_relay_t* +MultiHostNameRelay::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_multi_host_name_relay_t* +MultiHostNameRelay::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_multi_host_name_relay_t* +MultiHostNameRelay::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ MultiHostNameRelay::MultiHostNameRelay(cardano_multi_host_name_relay_t& value) noexcept diff --git a/lib/src/PoolParams/PoolMetadata.cpp b/lib/src/PoolParams/PoolMetadata.cpp index 423fc9a1..c93087b3 100644 --- a/lib/src/PoolParams/PoolMetadata.cpp +++ b/lib/src/PoolParams/PoolMetadata.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,7 +44,7 @@ PoolMetadata::PoolMetadata(std::string_view url, const Blake2bHash& hash) Blake2bHash copy(hash); cardano_pool_metadata_t* value = nullptr; - const cardano_error_t result = cardano_pool_metadata_new(url.empty() ? "" : url.data(), url.size(), copy.checked(), &value); + const cardano_error_t result = cardano_pool_metadata_new(url.empty() ? "" : url.data(), url.size(), checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -116,7 +118,7 @@ PoolMetadata::hash() const checkCardanoError(result, "PoolMetadata hash"); - const Blake2bHash data(owner.release()); + const Blake2bHash data = Blake2bHash::adopt(owner.release()); return Blake2bHash(data); } @@ -128,7 +130,7 @@ PoolMetadata::setHash(const Blake2bHash& hash) Blake2bHash copy(hash); - checkCardanoError(cardano_pool_metadata_set_hash(checked(), copy.checked()), "PoolMetadata setHash"); + checkCardanoError(cardano_pool_metadata_set_hash(checked(), checkedNativeHandle(copy)), "PoolMetadata setHash"); } std::vector @@ -186,6 +188,35 @@ PoolMetadata::operator!=(const PoolMetadata& other) const return !(*this == other); } +PoolMetadata +PoolMetadata::adopt(cardano_pool_metadata_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolMetadata"); + } + + return PoolMetadata(*value); +} + +cardano_pool_metadata_t* +PoolMetadata::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pool_metadata_t* +PoolMetadata::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_metadata_t* +PoolMetadata::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolMetadata::PoolMetadata(cardano_pool_metadata_t& value) noexcept diff --git a/lib/src/PoolParams/PoolOwners.cpp b/lib/src/PoolParams/PoolOwners.cpp index 3747bb0c..dba82ddc 100644 --- a/lib/src/PoolParams/PoolOwners.cpp +++ b/lib/src/PoolParams/PoolOwners.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -139,7 +141,7 @@ PoolOwners::contains(const Blake2bHash& value) const checkCardanoError(status, "PoolOwners contains"); - if (cardano_blake2b_hash_equals(owner.get(), value.checked())) + if (cardano_blake2b_hash_equals(owner.get(), checkedNativeHandle(value))) { return true; } @@ -161,7 +163,7 @@ PoolOwners::at(std::size_t index) const CardanoObject owner(element); checkCardanoError(status, "PoolOwners at"); - const Blake2bHash value(owner.release()); + const Blake2bHash value = Blake2bHash::adopt(owner.release()); return Blake2bHash(value); } @@ -435,6 +437,41 @@ PoolOwners::erase(const value_type& value) return 1; } +PoolOwners +PoolOwners::adopt(cardano_pool_owners_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolOwners"); + } + + return PoolOwners(value); +} + +cardano_pool_owners_t* +PoolOwners::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_pool_owners_t* +PoolOwners::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_owners_t* +PoolOwners::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolOwners::PoolOwners(cardano_pool_owners_t* value) noexcept @@ -507,7 +544,7 @@ PoolOwners::insertValue(const Blake2bHash& value) const Blake2bHash copy(value); - checkCardanoError(cardano_pool_owners_add(checked(), copy.checked()), "PoolOwners insert"); + checkCardanoError(cardano_pool_owners_add(checked(), checkedNativeHandle(copy)), "PoolOwners insert"); invalidateElements(); return true; diff --git a/lib/src/PoolParams/PoolParams.cpp b/lib/src/PoolParams/PoolParams.cpp index d1999fcd..e0f74f3d 100644 --- a/lib/src/PoolParams/PoolParams.cpp +++ b/lib/src/PoolParams/PoolParams.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -48,7 +50,7 @@ PoolParams::PoolParams(const Blake2bHash& operatorKeyHash, const Blake2bHash& vr const std::optional metadataCopy(metadata); cardano_pool_params_t* value = nullptr; - const cardano_error_t status = cardano_pool_params_new(operatorCopy.checked(), vrfCopy.checked(), pledge, cost, marginCopy.checked(), rewardCopy.checked(), ownersCopy.checked(), relaysCopy.checked(), metadataCopy ? metadataCopy->checked() : nullptr, &value); + const cardano_error_t status = cardano_pool_params_new(checkedNativeHandle(operatorCopy), checkedNativeHandle(vrfCopy), pledge, cost, checkedNativeHandle(marginCopy), checkedNativeHandle(rewardCopy), checkedNativeHandle(ownersCopy), checkedNativeHandle(relaysCopy), metadataCopy ? checkedNativeHandle(*metadataCopy) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "PoolParams"); @@ -130,7 +132,7 @@ PoolParams::operatorKeyHash() const CardanoObject owner(value); checkCardanoError(status, "PoolParams operatorKeyHash"); - const Blake2bHash result(owner.release()); + const Blake2bHash result = Blake2bHash::adopt(owner.release()); return Blake2bHash(result); } @@ -139,7 +141,7 @@ PoolParams::setOperatorKeyHash(const Blake2bHash& value) { validateHash(value, 28); const Blake2bHash copy(value); - checkCardanoError(cardano_pool_params_set_operator_key_hash(checked(), copy.checked()), "PoolParams set operatorKeyHash"); + checkCardanoError(cardano_pool_params_set_operator_key_hash(checked(), checkedNativeHandle(copy)), "PoolParams set operatorKeyHash"); } Blake2bHash @@ -150,7 +152,7 @@ PoolParams::vrfKeyHash() const CardanoObject owner(value); checkCardanoError(status, "PoolParams vrfKeyHash"); - const Blake2bHash result(owner.release()); + const Blake2bHash result = Blake2bHash::adopt(owner.release()); return Blake2bHash(result); } @@ -159,7 +161,7 @@ PoolParams::setVrfKeyHash(const Blake2bHash& value) { validateHash(value, 32); const Blake2bHash copy(value); - checkCardanoError(cardano_pool_params_set_vrf_vk_hash(checked(), copy.checked()), "PoolParams set vrfKeyHash"); + checkCardanoError(cardano_pool_params_set_vrf_vk_hash(checked(), checkedNativeHandle(copy)), "PoolParams set vrfKeyHash"); } UnitInterval @@ -170,7 +172,7 @@ PoolParams::margin() const CardanoObject owner(value); checkCardanoError(status, "PoolParams margin"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -178,7 +180,7 @@ void PoolParams::setMargin(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_params_set_margin(checked(), copy.checked()), "PoolParams set margin"); + checkCardanoError(cardano_pool_params_set_margin(checked(), checkedNativeHandle(copy)), "PoolParams set margin"); } RewardAddress @@ -189,7 +191,7 @@ PoolParams::rewardAccount() const CardanoObject owner(value); checkCardanoError(status, "PoolParams rewardAccount"); - const RewardAddress result(*owner.release()); + const RewardAddress result = RewardAddress::adopt(owner.release()); return RewardAddress(result); } @@ -197,7 +199,7 @@ void PoolParams::setRewardAccount(const RewardAddress& value) { const RewardAddress copy(value); - checkCardanoError(cardano_pool_params_set_reward_account(checked(), copy.checked()), "PoolParams set rewardAccount"); + checkCardanoError(cardano_pool_params_set_reward_account(checked(), checkedNativeHandle(copy)), "PoolParams set rewardAccount"); } PoolOwners @@ -208,7 +210,7 @@ PoolParams::owners() const CardanoObject owner(value); checkCardanoError(status, "PoolParams owners"); - const PoolOwners result(owner.release()); + const PoolOwners result = PoolOwners::adopt(owner.release()); return PoolOwners(result); } @@ -216,7 +218,7 @@ void PoolParams::setOwners(const PoolOwners& value) { const PoolOwners copy(value); - checkCardanoError(cardano_pool_params_set_owners(checked(), copy.checked()), "PoolParams set owners"); + checkCardanoError(cardano_pool_params_set_owners(checked(), checkedNativeHandle(copy)), "PoolParams set owners"); } Relays @@ -227,7 +229,7 @@ PoolParams::relays() const CardanoObject owner(value); checkCardanoError(status, "PoolParams relays"); - const Relays result(*owner.release()); + const Relays result = Relays::adopt(owner.release()); return Relays(result); } @@ -235,7 +237,7 @@ void PoolParams::setRelays(const Relays& value) { const Relays copy(value); - checkCardanoError(cardano_pool_params_set_relays(checked(), copy.checked()), "PoolParams set relays"); + checkCardanoError(cardano_pool_params_set_relays(checked(), checkedNativeHandle(copy)), "PoolParams set relays"); } std::optional @@ -251,7 +253,7 @@ PoolParams::blsKey() const return std::nullopt; } - const BlsKey result(*owner.release()); + const BlsKey result = BlsKey::adopt(owner.release()); return BlsKey(result); } @@ -259,7 +261,7 @@ void PoolParams::setBlsKey(const std::optional& value) { const std::optional copy(value); - checkCardanoError(cardano_pool_params_set_bls_key(checked(), copy ? copy->checked() : nullptr), "PoolParams set blsKey"); + checkCardanoError(cardano_pool_params_set_bls_key(checked(), copy ? checkedNativeHandle(*copy) : nullptr), "PoolParams set blsKey"); } std::optional @@ -275,7 +277,7 @@ PoolParams::metadata() const return std::nullopt; } - const PoolMetadata result(*owner.release()); + const PoolMetadata result = PoolMetadata::adopt(owner.release()); return PoolMetadata(result); } @@ -283,7 +285,7 @@ void PoolParams::setMetadata(const std::optional& value) { const std::optional copy(value); - checkCardanoError(cardano_pool_params_set_metadata(checked(), copy ? copy->checked() : nullptr), "PoolParams set metadata"); + checkCardanoError(cardano_pool_params_set_metadata(checked(), copy ? checkedNativeHandle(*copy) : nullptr), "PoolParams set metadata"); } std::vector @@ -343,6 +345,35 @@ PoolParams::operator!=(const PoolParams& other) const return !(*this == other); } +PoolParams +PoolParams::adopt(cardano_pool_params_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolParams"); + } + + return PoolParams(value); +} + +cardano_pool_params_t* +PoolParams::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pool_params_t* +PoolParams::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_params_t* +PoolParams::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolParams::PoolParams(cardano_pool_params_t* value) noexcept diff --git a/lib/src/PoolParams/Relay.cpp b/lib/src/PoolParams/Relay.cpp index 78623cde..45f982af 100644 --- a/lib/src/PoolParams/Relay.cpp +++ b/lib/src/PoolParams/Relay.cpp @@ -44,7 +44,7 @@ Relay::Relay(const SingleHostAddrRelay& relay) SingleHostAddrRelay copy(relay); cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_single_host_addr(copy.checked(), &value); + const cardano_error_t result = cardano_relay_new_single_host_addr(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -57,7 +57,7 @@ Relay::Relay(SingleHostAddrRelay&& relay) : m_value(nullptr) { cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_single_host_addr(relay.checked(), &value); + const cardano_error_t result = cardano_relay_new_single_host_addr(checkedNativeHandle(relay), &value); CardanoObject owner(value); @@ -74,7 +74,7 @@ Relay::Relay(const SingleHostNameRelay& relay) SingleHostNameRelay copy(relay); cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_single_host_name(copy.checked(), &value); + const cardano_error_t result = cardano_relay_new_single_host_name(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -87,7 +87,7 @@ Relay::Relay(SingleHostNameRelay&& relay) : m_value(nullptr) { cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_single_host_name(relay.checked(), &value); + const cardano_error_t result = cardano_relay_new_single_host_name(checkedNativeHandle(relay), &value); CardanoObject owner(value); @@ -104,7 +104,7 @@ Relay::Relay(const MultiHostNameRelay& relay) MultiHostNameRelay copy(relay); cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_multi_host_name(copy.checked(), &value); + const cardano_error_t result = cardano_relay_new_multi_host_name(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -117,7 +117,7 @@ Relay::Relay(MultiHostNameRelay&& relay) : m_value(nullptr) { cardano_relay_t* value = nullptr; - const cardano_error_t result = cardano_relay_new_multi_host_name(relay.checked(), &value); + const cardano_error_t result = cardano_relay_new_multi_host_name(checkedNativeHandle(relay), &value); CardanoObject owner(value); @@ -185,7 +185,7 @@ Relay::asSingleHostAddr() const checkCardanoError(result, "Relay asSingleHostAddr"); - const SingleHostAddrRelay relay(*owner.release()); + const SingleHostAddrRelay relay = SingleHostAddrRelay::adopt(owner.release()); return SingleHostAddrRelay(relay); } @@ -200,7 +200,7 @@ Relay::asSingleHostName() const checkCardanoError(result, "Relay asSingleHostName"); - const SingleHostNameRelay relay(*owner.release()); + const SingleHostNameRelay relay = SingleHostNameRelay::adopt(owner.release()); return SingleHostNameRelay(relay); } @@ -215,7 +215,7 @@ Relay::asMultiHostName() const checkCardanoError(result, "Relay asMultiHostName"); - const MultiHostNameRelay relay(*owner.release()); + const MultiHostNameRelay relay = MultiHostNameRelay::adopt(owner.release()); return MultiHostNameRelay(relay); } @@ -275,6 +275,35 @@ Relay::operator!=(const Relay& other) const return !(*this == other); } +Relay +Relay::adopt(cardano_relay_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Relay"); + } + + return Relay(*value); +} + +cardano_relay_t* +Relay::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_relay_t* +Relay::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_relay_t* +Relay::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Relay::Relay(cardano_relay_t& value) noexcept diff --git a/lib/src/PoolParams/Relays.cpp b/lib/src/PoolParams/Relays.cpp index 59af29f0..a2fba162 100644 --- a/lib/src/PoolParams/Relays.cpp +++ b/lib/src/PoolParams/Relays.cpp @@ -36,6 +36,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -131,7 +133,7 @@ Relays::pushBack(const Relay& relay) Relay copy(relay); - checkCardanoError(cardano_relays_add(checked(), copy.checked()), "Relays pushBack"); + checkCardanoError(cardano_relays_add(checked(), checkedNativeHandle(copy)), "Relays pushBack"); } std::vector @@ -471,6 +473,60 @@ Relays::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +Relays +Relays::adopt(cardano_relays_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Relays"); + } + + return Relays(*value); +} + +cardano_relays_t* +Relays::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_relays_t* +Relays::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_relays_t* +Relays::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Relays::Relays(cardano_relays_t& value) noexcept @@ -564,7 +620,7 @@ Relays::copyElement(std::size_t index) const checkCardanoError(result, "Relays at"); - const Relay relay(*owner.release()); + const Relay relay = Relay::adopt(owner.release()); return Relay(relay); } diff --git a/lib/src/PoolParams/SingleHostAddrRelay.cpp b/lib/src/PoolParams/SingleHostAddrRelay.cpp index ab0b0712..0abf5bf0 100644 --- a/lib/src/PoolParams/SingleHostAddrRelay.cpp +++ b/lib/src/PoolParams/SingleHostAddrRelay.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ SingleHostAddrRelay::SingleHostAddrRelay(std::optional port, cons const std::optional v6(ipv6); cardano_single_host_addr_relay_t* value = nullptr; - const cardano_error_t result = cardano_single_host_addr_relay_new(port ? &*port : nullptr, v4 ? v4->checked() : nullptr, v6 ? v6->checked() : nullptr, &value); + const cardano_error_t result = cardano_single_host_addr_relay_new(port ? &*port : nullptr, v4 ? checkedNativeHandle(*v4) : nullptr, v6 ? checkedNativeHandle(*v6) : nullptr, &value); CardanoObject owner(value); @@ -115,7 +117,7 @@ SingleHostAddrRelay::ipv4() const return std::nullopt; } - const Ipv4 address(*owner.release()); + const Ipv4 address = Ipv4::adopt(owner.release()); return Ipv4(address); } @@ -143,7 +145,7 @@ SingleHostAddrRelay::ipv6() const return std::nullopt; } - const Ipv6 address(*owner.release()); + const Ipv6 address = Ipv6::adopt(owner.release()); return Ipv6(address); } @@ -211,6 +213,35 @@ SingleHostAddrRelay::operator!=(const SingleHostAddrRelay& other) const return !(*this == other); } +SingleHostAddrRelay +SingleHostAddrRelay::adopt(cardano_single_host_addr_relay_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null SingleHostAddrRelay"); + } + + return SingleHostAddrRelay(*value); +} + +cardano_single_host_addr_relay_t* +SingleHostAddrRelay::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_single_host_addr_relay_t* +SingleHostAddrRelay::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_single_host_addr_relay_t* +SingleHostAddrRelay::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ SingleHostAddrRelay::SingleHostAddrRelay(cardano_single_host_addr_relay_t& value) noexcept diff --git a/lib/src/PoolParams/SingleHostNameRelay.cpp b/lib/src/PoolParams/SingleHostNameRelay.cpp index d20af89d..3566ad7c 100644 --- a/lib/src/PoolParams/SingleHostNameRelay.cpp +++ b/lib/src/PoolParams/SingleHostNameRelay.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -170,6 +172,35 @@ SingleHostNameRelay::operator!=(const SingleHostNameRelay& other) const return !(*this == other); } +SingleHostNameRelay +SingleHostNameRelay::adopt(cardano_single_host_name_relay_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null SingleHostNameRelay"); + } + + return SingleHostNameRelay(*value); +} + +cardano_single_host_name_relay_t* +SingleHostNameRelay::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_single_host_name_relay_t* +SingleHostNameRelay::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_single_host_name_relay_t* +SingleHostNameRelay::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ SingleHostNameRelay::SingleHostNameRelay(cardano_single_host_name_relay_t& value) noexcept diff --git a/lib/src/ProposalProcedures/Committee.cpp b/lib/src/ProposalProcedures/Committee.cpp index e89aad3e..114dcf25 100644 --- a/lib/src/ProposalProcedures/Committee.cpp +++ b/lib/src/ProposalProcedures/Committee.cpp @@ -32,6 +32,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -41,7 +43,7 @@ Committee::Committee(const UnitInterval& quorumThreshold) { const UnitInterval copy(quorumThreshold); cardano_committee_t* value = nullptr; - const cardano_error_t status = cardano_committee_new(copy.checked(), &value); + const cardano_error_t status = cardano_committee_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); checkCardanoError(status, "Committee"); @@ -92,7 +94,7 @@ Committee::quorumThreshold() const throw std::logic_error("Committee has no quorum threshold"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -100,14 +102,14 @@ void Committee::setQuorumThreshold(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_committee_set_quorum_threshold(checked(), copy.checked()), "Committee setQuorumThreshold"); + checkCardanoError(cardano_committee_set_quorum_threshold(checked(), checkedNativeHandle(copy)), "Committee setQuorumThreshold"); } void Committee::addMember(const Credential& credential, std::uint64_t epoch) { const Credential copy(credential); - checkCardanoError(cardano_committee_add_member(checked(), copy.checked(), epoch), "Committee addMember"); + checkCardanoError(cardano_committee_add_member(checked(), checkedNativeHandle(copy), epoch), "Committee addMember"); } CredentialSet @@ -118,13 +120,13 @@ Committee::keys() const CardanoObject owner(value); checkCardanoError(status, "Committee keys"); - return CredentialSet(owner.release()); + return CredentialSet::adopt(owner.release()); } std::uint64_t Committee::memberEpoch(const Credential& credential) const { - return cardano_committee_get_member_epoch(checked(), credential.checked()); + return cardano_committee_get_member_epoch(checked(), checkedNativeHandle(credential)); } Credential @@ -140,7 +142,7 @@ Committee::keyAt(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "Committee keyAt"); - const Credential found(owner.release()); + const Credential found = Credential::adopt(owner.release()); return Credential(found); } @@ -171,7 +173,7 @@ Committee::at(std::size_t index) const CardanoObject owner(key); checkCardanoError(status, "Committee at"); - const Credential found(owner.release()); + const Credential found = Credential::adopt(owner.release()); return { Credential(found), epoch }; } @@ -221,6 +223,35 @@ Committee::operator!=(const Committee& other) const return !(*this == other); } +Committee +Committee::adopt(cardano_committee_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Committee"); + } + + return Committee(value); +} + +cardano_committee_t* +Committee::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_committee_t* +Committee::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_committee_t* +Committee::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Committee::Committee(cardano_committee_t* value) noexcept diff --git a/lib/src/ProposalProcedures/CommitteeMembersMap.cpp b/lib/src/ProposalProcedures/CommitteeMembersMap.cpp index e7c2e35d..e5008f8e 100644 --- a/lib/src/ProposalProcedures/CommitteeMembersMap.cpp +++ b/lib/src/ProposalProcedures/CommitteeMembersMap.cpp @@ -31,6 +31,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -98,7 +100,7 @@ void CommitteeMembersMap::insert(const Credential& credential, std::uint64_t epoch) { const Credential copy(credential); - checkCardanoError(cardano_committee_members_map_insert(checked(), copy.checked(), epoch), "CommitteeMembersMap insert"); + checkCardanoError(cardano_committee_members_map_insert(checked(), checkedNativeHandle(copy), epoch), "CommitteeMembersMap insert"); invalidateElements(); } @@ -106,7 +108,7 @@ std::optional CommitteeMembersMap::get(const Credential& credential) const { std::uint64_t value = 0; - const cardano_error_t status = cardano_committee_members_map_get(checked(), credential.checked(), &value); + const cardano_error_t status = cardano_committee_members_map_get(checked(), checkedNativeHandle(credential), &value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -125,7 +127,7 @@ CommitteeMembersMap::keys() const CardanoObject owner(value); checkCardanoError(status, "CommitteeMembersMap keys"); - return CredentialSet(owner.release()); + return CredentialSet::adopt(owner.release()); } Credential @@ -141,7 +143,7 @@ CommitteeMembersMap::keyAt(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "CommitteeMembersMap keyAt"); - const Credential found(owner.release()); + const Credential found = Credential::adopt(owner.release()); return Credential(found); } @@ -172,7 +174,7 @@ CommitteeMembersMap::at(std::size_t index) const CardanoObject owner(key); checkCardanoError(status, "CommitteeMembersMap at"); - const Credential found(owner.release()); + const Credential found = Credential::adopt(owner.release()); return { Credential(found), epoch }; } @@ -469,6 +471,60 @@ CommitteeMembersMap::empty() const return size() == 0; } +CommitteeMembersMap +CommitteeMembersMap::adopt(cardano_committee_members_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CommitteeMembersMap"); + } + + return CommitteeMembersMap(value); +} + +cardano_committee_members_map_t* +CommitteeMembersMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_committee_members_map_t* +CommitteeMembersMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_committee_members_map_t* +CommitteeMembersMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ CommitteeMembersMap::CommitteeMembersMap(cardano_committee_members_map_t* value) noexcept diff --git a/lib/src/ProposalProcedures/Constitution.cpp b/lib/src/ProposalProcedures/Constitution.cpp index 347c0a3c..9f95c22e 100644 --- a/lib/src/ProposalProcedures/Constitution.cpp +++ b/lib/src/ProposalProcedures/Constitution.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,9 +40,9 @@ Constitution::Constitution(const Anchor& anchor, const std::optional scriptCopy(scriptHash); - cardano_blake2b_hash_t* script = scriptCopy ? scriptCopy->checked() : nullptr; + cardano_blake2b_hash_t* script = scriptCopy ? checkedNativeHandle(*scriptCopy) : nullptr; cardano_constitution_t* value = nullptr; - const cardano_error_t status = cardano_constitution_new(anchorCopy.checked(), script, &value); + const cardano_error_t status = cardano_constitution_new(checkedNativeHandle(anchorCopy), script, &value); CardanoObject owner(value); checkCardanoError(status, "Constitution"); @@ -91,7 +93,7 @@ Constitution::anchor() const throw std::logic_error("Constitution has no anchor"); } - const Anchor found(owner.release()); + const Anchor found = Anchor::adopt(owner.release()); return Anchor(found); } @@ -99,7 +101,7 @@ void Constitution::setAnchor(const Anchor& value) { const Anchor copy(value); - checkCardanoError(cardano_constitution_set_anchor(checked(), copy.checked()), "Constitution setAnchor"); + checkCardanoError(cardano_constitution_set_anchor(checked(), checkedNativeHandle(copy)), "Constitution setAnchor"); } std::optional @@ -113,7 +115,7 @@ Constitution::scriptHash() const return std::nullopt; } - const Blake2bHash found(owner.release()); + const Blake2bHash found = Blake2bHash::adopt(owner.release()); return Blake2bHash(found); } @@ -121,7 +123,7 @@ void Constitution::setScriptHash(const std::optional& value) { const std::optional copy(value); - cardano_blake2b_hash_t* data = copy ? copy->checked() : nullptr; + cardano_blake2b_hash_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_constitution_set_script_hash(checked(), data), "Constitution setScriptHash"); } @@ -177,6 +179,35 @@ Constitution::operator!=(const Constitution& other) const return !(*this == other); } +Constitution +Constitution::adopt(cardano_constitution_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Constitution"); + } + + return Constitution(value); +} + +cardano_constitution_t* +Constitution::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_constitution_t* +Constitution::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_constitution_t* +Constitution::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Constitution::Constitution(cardano_constitution_t* value) noexcept diff --git a/lib/src/ProposalProcedures/HardForkInitiationAction.cpp b/lib/src/ProposalProcedures/HardForkInitiationAction.cpp index cc57b53c..f152b4da 100644 --- a/lib/src/ProposalProcedures/HardForkInitiationAction.cpp +++ b/lib/src/ProposalProcedures/HardForkInitiationAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,9 +40,9 @@ HardForkInitiationAction::HardForkInitiationAction(const ProtocolVersion& versio { const ProtocolVersion versionCopy(version); const std::optional previousCopy(previousAction); - cardano_governance_action_id_t* previous = previousCopy ? previousCopy->checked() : nullptr; + cardano_governance_action_id_t* previous = previousCopy ? checkedNativeHandle(*previousCopy) : nullptr; cardano_hard_fork_initiation_action_t* value = nullptr; - const cardano_error_t status = cardano_hard_fork_initiation_action_new(versionCopy.checked(), previous, &value); + const cardano_error_t status = cardano_hard_fork_initiation_action_new(checkedNativeHandle(versionCopy), previous, &value); CardanoObject owner(value); checkCardanoError(status, "HardForkInitiationAction"); @@ -91,7 +93,7 @@ HardForkInitiationAction::version() const throw std::logic_error("HardForkInitiationAction has no protocol version"); } - const ProtocolVersion found(owner.release()); + const ProtocolVersion found = ProtocolVersion::adopt(owner.release()); return ProtocolVersion(found); } @@ -99,7 +101,7 @@ void HardForkInitiationAction::setVersion(const ProtocolVersion& value) { const ProtocolVersion copy(value); - checkCardanoError(cardano_hard_fork_initiation_action_set_protocol_version(checked(), copy.checked()), "HardForkInitiationAction setVersion"); + checkCardanoError(cardano_hard_fork_initiation_action_set_protocol_version(checked(), checkedNativeHandle(copy)), "HardForkInitiationAction setVersion"); } std::optional @@ -113,7 +115,7 @@ HardForkInitiationAction::previousAction() const return std::nullopt; } - const GovernanceActionId found(owner.release()); + const GovernanceActionId found = GovernanceActionId::adopt(owner.release()); return GovernanceActionId(found); } @@ -121,7 +123,7 @@ void HardForkInitiationAction::setPreviousAction(const std::optional& value) { const std::optional copy(value); - cardano_governance_action_id_t* data = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_hard_fork_initiation_action_set_governance_action_id(checked(), data), "HardForkInitiationAction setPreviousAction"); } @@ -177,6 +179,35 @@ HardForkInitiationAction::operator!=(const HardForkInitiationAction& other) cons return !(*this == other); } +HardForkInitiationAction +HardForkInitiationAction::adopt(cardano_hard_fork_initiation_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null HardForkInitiationAction"); + } + + return HardForkInitiationAction(value); +} + +cardano_hard_fork_initiation_action_t* +HardForkInitiationAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_hard_fork_initiation_action_t* +HardForkInitiationAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_hard_fork_initiation_action_t* +HardForkInitiationAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ HardForkInitiationAction::HardForkInitiationAction(cardano_hard_fork_initiation_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/InfoAction.cpp b/lib/src/ProposalProcedures/InfoAction.cpp index 9b0791e9..6d637aae 100644 --- a/lib/src/ProposalProcedures/InfoAction.cpp +++ b/lib/src/ProposalProcedures/InfoAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -129,6 +131,35 @@ InfoAction::operator!=(const InfoAction& other) const return !(*this == other); } +InfoAction +InfoAction::adopt(cardano_info_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null InfoAction"); + } + + return InfoAction(value); +} + +cardano_info_action_t* +InfoAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_info_action_t* +InfoAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_info_action_t* +InfoAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ InfoAction::InfoAction(cardano_info_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/NewConstitutionAction.cpp b/lib/src/ProposalProcedures/NewConstitutionAction.cpp index 4cefc19b..92923ee6 100644 --- a/lib/src/ProposalProcedures/NewConstitutionAction.cpp +++ b/lib/src/ProposalProcedures/NewConstitutionAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,9 +40,9 @@ NewConstitutionAction::NewConstitutionAction(const Constitution& constitution, c { const Constitution constitutionCopy(constitution); const std::optional previousCopy(previousAction); - cardano_governance_action_id_t* previous = previousCopy ? previousCopy->checked() : nullptr; + cardano_governance_action_id_t* previous = previousCopy ? checkedNativeHandle(*previousCopy) : nullptr; cardano_new_constitution_action_t* value = nullptr; - const cardano_error_t status = cardano_new_constitution_action_new(constitutionCopy.checked(), previous, &value); + const cardano_error_t status = cardano_new_constitution_action_new(checkedNativeHandle(constitutionCopy), previous, &value); CardanoObject owner(value); checkCardanoError(status, "NewConstitutionAction"); @@ -91,7 +93,7 @@ NewConstitutionAction::constitution() const throw std::logic_error("NewConstitutionAction has no constitution"); } - const Constitution found(owner.release()); + const Constitution found = Constitution::adopt(owner.release()); return Constitution(found); } @@ -99,7 +101,7 @@ void NewConstitutionAction::setConstitution(const Constitution& value) { const Constitution copy(value); - checkCardanoError(cardano_new_constitution_action_set_constitution(checked(), copy.checked()), "NewConstitutionAction setConstitution"); + checkCardanoError(cardano_new_constitution_action_set_constitution(checked(), checkedNativeHandle(copy)), "NewConstitutionAction setConstitution"); } std::optional @@ -113,7 +115,7 @@ NewConstitutionAction::previousAction() const return std::nullopt; } - const GovernanceActionId found(owner.release()); + const GovernanceActionId found = GovernanceActionId::adopt(owner.release()); return GovernanceActionId(found); } @@ -121,7 +123,7 @@ void NewConstitutionAction::setPreviousAction(const std::optional& value) { const std::optional copy(value); - cardano_governance_action_id_t* data = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_new_constitution_action_set_governance_action_id(checked(), data), "NewConstitutionAction setPreviousAction"); } @@ -177,6 +179,35 @@ NewConstitutionAction::operator!=(const NewConstitutionAction& other) const return !(*this == other); } +NewConstitutionAction +NewConstitutionAction::adopt(cardano_new_constitution_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null NewConstitutionAction"); + } + + return NewConstitutionAction(value); +} + +cardano_new_constitution_action_t* +NewConstitutionAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_new_constitution_action_t* +NewConstitutionAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_new_constitution_action_t* +NewConstitutionAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ NewConstitutionAction::NewConstitutionAction(cardano_new_constitution_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/NoConfidenceAction.cpp b/lib/src/ProposalProcedures/NoConfidenceAction.cpp index 895f5e71..9eaed1df 100644 --- a/lib/src/ProposalProcedures/NoConfidenceAction.cpp +++ b/lib/src/ProposalProcedures/NoConfidenceAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -37,7 +39,7 @@ NoConfidenceAction::NoConfidenceAction(const std::optional& : m_value(nullptr) { const std::optional copy(previousAction); - cardano_governance_action_id_t* previous = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* previous = copy ? checkedNativeHandle(*copy) : nullptr; cardano_no_confidence_action_t* value = nullptr; const cardano_error_t status = cardano_no_confidence_action_new(previous, &value); CardanoObject owner(value); @@ -90,7 +92,7 @@ NoConfidenceAction::previousAction() const return std::nullopt; } - const GovernanceActionId found(owner.release()); + const GovernanceActionId found = GovernanceActionId::adopt(owner.release()); return GovernanceActionId(found); } @@ -98,7 +100,7 @@ void NoConfidenceAction::setPreviousAction(const std::optional& value) { const std::optional copy(value); - cardano_governance_action_id_t* data = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_no_confidence_action_set_governance_action_id(checked(), data), "NoConfidenceAction setPreviousAction"); } @@ -154,6 +156,35 @@ NoConfidenceAction::operator!=(const NoConfidenceAction& other) const return !(*this == other); } +NoConfidenceAction +NoConfidenceAction::adopt(cardano_no_confidence_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null NoConfidenceAction"); + } + + return NoConfidenceAction(value); +} + +cardano_no_confidence_action_t* +NoConfidenceAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_no_confidence_action_t* +NoConfidenceAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_no_confidence_action_t* +NoConfidenceAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ NoConfidenceAction::NoConfidenceAction(cardano_no_confidence_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/ParameterChangeAction.cpp b/lib/src/ProposalProcedures/ParameterChangeAction.cpp index dc45eccb..7a781b50 100644 --- a/lib/src/ProposalProcedures/ParameterChangeAction.cpp +++ b/lib/src/ProposalProcedures/ParameterChangeAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,10 +44,10 @@ ParameterChangeAction::ParameterChangeAction( const ProtocolParamUpdate updateCopy(update); const std::optional previousCopy(previousAction); const std::optional policyCopy(policyHash); - cardano_governance_action_id_t* previous = previousCopy ? previousCopy->checked() : nullptr; - cardano_blake2b_hash_t* policy = policyCopy ? policyCopy->checked() : nullptr; + cardano_governance_action_id_t* previous = previousCopy ? checkedNativeHandle(*previousCopy) : nullptr; + cardano_blake2b_hash_t* policy = policyCopy ? checkedNativeHandle(*policyCopy) : nullptr; cardano_parameter_change_action_t* value = nullptr; - const cardano_error_t status = cardano_parameter_change_action_new(updateCopy.checked(), previous, policy, &value); + const cardano_error_t status = cardano_parameter_change_action_new(checkedNativeHandle(updateCopy), previous, policy, &value); CardanoObject owner(value); checkCardanoError(status, "ParameterChangeAction"); @@ -96,7 +98,7 @@ ParameterChangeAction::update() const throw std::logic_error("ParameterChangeAction has no parameter update"); } - const ProtocolParamUpdate found(owner.release()); + const ProtocolParamUpdate found = ProtocolParamUpdate::adopt(owner.release()); return ProtocolParamUpdate(found); } @@ -104,7 +106,7 @@ void ParameterChangeAction::setUpdate(const ProtocolParamUpdate& value) { const ProtocolParamUpdate copy(value); - checkCardanoError(cardano_parameter_change_action_set_protocol_param_update(checked(), copy.checked()), "ParameterChangeAction setUpdate"); + checkCardanoError(cardano_parameter_change_action_set_protocol_param_update(checked(), checkedNativeHandle(copy)), "ParameterChangeAction setUpdate"); } std::optional @@ -118,7 +120,7 @@ ParameterChangeAction::policyHash() const return std::nullopt; } - const Blake2bHash found(owner.release()); + const Blake2bHash found = Blake2bHash::adopt(owner.release()); return Blake2bHash(found); } @@ -126,7 +128,7 @@ void ParameterChangeAction::setPolicyHash(const std::optional& value) { const std::optional copy(value); - cardano_blake2b_hash_t* data = copy ? copy->checked() : nullptr; + cardano_blake2b_hash_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_parameter_change_action_set_policy_hash(checked(), data), "ParameterChangeAction setPolicyHash"); } @@ -141,7 +143,7 @@ ParameterChangeAction::previousAction() const return std::nullopt; } - const GovernanceActionId found(owner.release()); + const GovernanceActionId found = GovernanceActionId::adopt(owner.release()); return GovernanceActionId(found); } @@ -149,7 +151,7 @@ void ParameterChangeAction::setPreviousAction(const std::optional& value) { const std::optional copy(value); - cardano_governance_action_id_t* data = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_parameter_change_action_set_governance_action_id(checked(), data), "ParameterChangeAction setPreviousAction"); } @@ -205,6 +207,35 @@ ParameterChangeAction::operator!=(const ParameterChangeAction& other) const return !(*this == other); } +ParameterChangeAction +ParameterChangeAction::adopt(cardano_parameter_change_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ParameterChangeAction"); + } + + return ParameterChangeAction(value); +} + +cardano_parameter_change_action_t* +ParameterChangeAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_parameter_change_action_t* +ParameterChangeAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_parameter_change_action_t* +ParameterChangeAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ParameterChangeAction::ParameterChangeAction(cardano_parameter_change_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/ProposalProcedure.cpp b/lib/src/ProposalProcedures/ProposalProcedure.cpp index d4713cb6..fe624609 100644 --- a/lib/src/ProposalProcedures/ProposalProcedure.cpp +++ b/lib/src/ProposalProcedures/ProposalProcedure.cpp @@ -38,6 +38,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -49,7 +51,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const ParameterChangeAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_parameter_change_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_parameter_change_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure ParameterChangeAction"); @@ -63,7 +65,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const HardForkInitiationAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_hard_fork_initiation_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_hard_fork_initiation_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure HardForkInitiationAction"); @@ -77,7 +79,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const TreasuryWithdrawalsAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_treasury_withdrawals_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_treasury_withdrawals_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure TreasuryWithdrawalsAction"); @@ -91,7 +93,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const NoConfidenceAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_no_confidence_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_no_confidence_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure NoConfidenceAction"); @@ -105,7 +107,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const UpdateCommitteeAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_update_committee_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_update_committee_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure UpdateCommitteeAction"); @@ -119,7 +121,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const NewConstitutionAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_constitution_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_constitution_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure NewConstitutionAction"); @@ -133,7 +135,7 @@ ProposalProcedure::ProposalProcedure(std::uint64_t deposit, const RewardAddress& const Anchor anchorCopy(anchor); const InfoAction actionCopy(action); cardano_proposal_procedure_t* value = nullptr; - const cardano_error_t status = cardano_proposal_procedure_new_info_action(deposit, addressCopy.checked(), anchorCopy.checked(), actionCopy.checked(), &value); + const cardano_error_t status = cardano_proposal_procedure_new_info_action(deposit, checkedNativeHandle(addressCopy), checkedNativeHandle(anchorCopy), checkedNativeHandle(actionCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure InfoAction"); @@ -194,7 +196,7 @@ ProposalProcedure::asParameterChangeAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asParameterChangeAction"); - const ParameterChangeAction found(owner.release()); + const ParameterChangeAction found = ParameterChangeAction::adopt(owner.release()); return ParameterChangeAction(found); } @@ -211,7 +213,7 @@ ProposalProcedure::asHardForkInitiationAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asHardForkInitiationAction"); - const HardForkInitiationAction found(owner.release()); + const HardForkInitiationAction found = HardForkInitiationAction::adopt(owner.release()); return HardForkInitiationAction(found); } @@ -228,7 +230,7 @@ ProposalProcedure::asTreasuryWithdrawalsAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asTreasuryWithdrawalsAction"); - const TreasuryWithdrawalsAction found(owner.release()); + const TreasuryWithdrawalsAction found = TreasuryWithdrawalsAction::adopt(owner.release()); return TreasuryWithdrawalsAction(found); } @@ -245,7 +247,7 @@ ProposalProcedure::asNoConfidenceAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asNoConfidenceAction"); - const NoConfidenceAction found(owner.release()); + const NoConfidenceAction found = NoConfidenceAction::adopt(owner.release()); return NoConfidenceAction(found); } @@ -262,7 +264,7 @@ ProposalProcedure::asUpdateCommitteeAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asUpdateCommitteeAction"); - const UpdateCommitteeAction found(owner.release()); + const UpdateCommitteeAction found = UpdateCommitteeAction::adopt(owner.release()); return UpdateCommitteeAction(found); } @@ -279,7 +281,7 @@ ProposalProcedure::asNewConstitutionAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asNewConstitutionAction"); - const NewConstitutionAction found(owner.release()); + const NewConstitutionAction found = NewConstitutionAction::adopt(owner.release()); return NewConstitutionAction(found); } @@ -296,7 +298,7 @@ ProposalProcedure::asInfoAction() const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedure asInfoAction"); - const InfoAction found(owner.release()); + const InfoAction found = InfoAction::adopt(owner.release()); return InfoAction(found); } @@ -323,7 +325,7 @@ ProposalProcedure::rewardAddress() const throw std::logic_error("ProposalProcedure has no reward address"); } - const RewardAddress found(*owner.release()); + const RewardAddress found = RewardAddress::adopt(owner.release()); return RewardAddress(found); } @@ -331,7 +333,7 @@ void ProposalProcedure::setRewardAddress(const RewardAddress& value) { const RewardAddress copy(value); - checkCardanoError(cardano_proposal_procedure_set_reward_address(checked(), copy.checked()), "ProposalProcedure setRewardAddress"); + checkCardanoError(cardano_proposal_procedure_set_reward_address(checked(), checkedNativeHandle(copy)), "ProposalProcedure setRewardAddress"); } Anchor @@ -345,7 +347,7 @@ ProposalProcedure::anchor() const throw std::logic_error("ProposalProcedure has no anchor"); } - const Anchor found(owner.release()); + const Anchor found = Anchor::adopt(owner.release()); return Anchor(found); } @@ -353,7 +355,7 @@ void ProposalProcedure::setAnchor(const Anchor& value) { const Anchor copy(value); - checkCardanoError(cardano_proposal_procedure_set_anchor(checked(), copy.checked()), "ProposalProcedure setAnchor"); + checkCardanoError(cardano_proposal_procedure_set_anchor(checked(), checkedNativeHandle(copy)), "ProposalProcedure setAnchor"); } std::vector @@ -408,6 +410,35 @@ ProposalProcedure::operator!=(const ProposalProcedure& other) const return !(*this == other); } +ProposalProcedure +ProposalProcedure::adopt(cardano_proposal_procedure_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProposalProcedure"); + } + + return ProposalProcedure(value); +} + +cardano_proposal_procedure_t* +ProposalProcedure::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_proposal_procedure_t* +ProposalProcedure::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_proposal_procedure_t* +ProposalProcedure::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ProposalProcedure::ProposalProcedure(cardano_proposal_procedure_t* value) noexcept diff --git a/lib/src/ProposalProcedures/ProposalProcedureSet.cpp b/lib/src/ProposalProcedures/ProposalProcedureSet.cpp index e313c8d4..ef0315aa 100644 --- a/lib/src/ProposalProcedures/ProposalProcedureSet.cpp +++ b/lib/src/ProposalProcedures/ProposalProcedureSet.cpp @@ -33,6 +33,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -106,7 +108,7 @@ ProposalProcedureSet::add(const ProposalProcedure& value) } const ProposalProcedure copy(value); - checkCardanoError(cardano_proposal_procedure_set_add(checked(), copy.checked()), "ProposalProcedureSet add"); + checkCardanoError(cardano_proposal_procedure_set_add(checked(), checkedNativeHandle(copy)), "ProposalProcedureSet add"); } std::vector @@ -433,6 +435,60 @@ ProposalProcedureSet::empty() const return size() == 0; } +ProposalProcedureSet +ProposalProcedureSet::adopt(cardano_proposal_procedure_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProposalProcedureSet"); + } + + return ProposalProcedureSet(value); +} + +cardano_proposal_procedure_set_t* +ProposalProcedureSet::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_proposal_procedure_set_t* +ProposalProcedureSet::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_proposal_procedure_set_t* +ProposalProcedureSet::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ProposalProcedureSet::ProposalProcedureSet(cardano_proposal_procedure_set_t* value) noexcept @@ -523,7 +579,7 @@ ProposalProcedureSet::copyElement(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "ProposalProcedureSet at"); - const ProposalProcedure copied(owner.release()); + const ProposalProcedure copied = ProposalProcedure::adopt(owner.release()); return ProposalProcedure(copied); } diff --git a/lib/src/ProposalProcedures/TreasuryWithdrawalsAction.cpp b/lib/src/ProposalProcedures/TreasuryWithdrawalsAction.cpp index a5d46c60..3fe39f76 100644 --- a/lib/src/ProposalProcedures/TreasuryWithdrawalsAction.cpp +++ b/lib/src/ProposalProcedures/TreasuryWithdrawalsAction.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,9 +40,9 @@ TreasuryWithdrawalsAction::TreasuryWithdrawalsAction(const WithdrawalMap& withdr { const WithdrawalMap withdrawalsCopy(withdrawals); const std::optional policyCopy(policyHash); - cardano_blake2b_hash_t* policy = policyCopy ? policyCopy->checked() : nullptr; + cardano_blake2b_hash_t* policy = policyCopy ? checkedNativeHandle(*policyCopy) : nullptr; cardano_treasury_withdrawals_action_t* value = nullptr; - const cardano_error_t status = cardano_treasury_withdrawals_action_new(withdrawalsCopy.checked(), policy, &value); + const cardano_error_t status = cardano_treasury_withdrawals_action_new(checkedNativeHandle(withdrawalsCopy), policy, &value); CardanoObject owner(value); checkCardanoError(status, "TreasuryWithdrawalsAction"); @@ -91,7 +93,7 @@ TreasuryWithdrawalsAction::withdrawals() const throw std::logic_error("TreasuryWithdrawalsAction has no withdrawals"); } - const WithdrawalMap found(*owner.release()); + const WithdrawalMap found = WithdrawalMap::adopt(owner.release()); return WithdrawalMap(found); } @@ -99,7 +101,7 @@ void TreasuryWithdrawalsAction::setWithdrawals(const WithdrawalMap& value) { const WithdrawalMap copy(value); - checkCardanoError(cardano_treasury_withdrawals_action_set_withdrawals(checked(), copy.checked()), "TreasuryWithdrawalsAction setWithdrawals"); + checkCardanoError(cardano_treasury_withdrawals_action_set_withdrawals(checked(), checkedNativeHandle(copy)), "TreasuryWithdrawalsAction setWithdrawals"); } std::optional @@ -113,7 +115,7 @@ TreasuryWithdrawalsAction::policyHash() const return std::nullopt; } - const Blake2bHash found(owner.release()); + const Blake2bHash found = Blake2bHash::adopt(owner.release()); return Blake2bHash(found); } @@ -121,7 +123,7 @@ void TreasuryWithdrawalsAction::setPolicyHash(const std::optional& value) { const std::optional copy(value); - cardano_blake2b_hash_t* data = copy ? copy->checked() : nullptr; + cardano_blake2b_hash_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_treasury_withdrawals_action_set_policy_hash(checked(), data), "TreasuryWithdrawalsAction setPolicyHash"); } @@ -177,6 +179,35 @@ TreasuryWithdrawalsAction::operator!=(const TreasuryWithdrawalsAction& other) co return !(*this == other); } +TreasuryWithdrawalsAction +TreasuryWithdrawalsAction::adopt(cardano_treasury_withdrawals_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null TreasuryWithdrawalsAction"); + } + + return TreasuryWithdrawalsAction(value); +} + +cardano_treasury_withdrawals_action_t* +TreasuryWithdrawalsAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_treasury_withdrawals_action_t* +TreasuryWithdrawalsAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_treasury_withdrawals_action_t* +TreasuryWithdrawalsAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ TreasuryWithdrawalsAction::TreasuryWithdrawalsAction(cardano_treasury_withdrawals_action_t* value) noexcept diff --git a/lib/src/ProposalProcedures/UpdateCommitteeAction.cpp b/lib/src/ProposalProcedures/UpdateCommitteeAction.cpp index 2ea840b0..d2c8d258 100644 --- a/lib/src/ProposalProcedures/UpdateCommitteeAction.cpp +++ b/lib/src/ProposalProcedures/UpdateCommitteeAction.cpp @@ -33,6 +33,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -44,9 +46,9 @@ UpdateCommitteeAction::UpdateCommitteeAction(const CredentialSet& removed, const const CommitteeMembersMap addedCopy(added); const UnitInterval quorumCopy(quorum); const std::optional previousCopy(previousAction); - cardano_governance_action_id_t* previous = previousCopy ? previousCopy->checked() : nullptr; + cardano_governance_action_id_t* previous = previousCopy ? checkedNativeHandle(*previousCopy) : nullptr; cardano_update_committee_action_t* value = nullptr; - const cardano_error_t status = cardano_update_committee_action_new(removedCopy.checked(), addedCopy.checked(), quorumCopy.checked(), previous, &value); + const cardano_error_t status = cardano_update_committee_action_new(checkedNativeHandle(removedCopy), checkedNativeHandle(addedCopy), checkedNativeHandle(quorumCopy), previous, &value); CardanoObject owner(value); checkCardanoError(status, "UpdateCommitteeAction"); @@ -97,7 +99,7 @@ UpdateCommitteeAction::removedMembers() const throw std::logic_error("UpdateCommitteeAction has no removed members"); } - const CredentialSet found(owner.release()); + const CredentialSet found = CredentialSet::adopt(owner.release()); return CredentialSet(found); } @@ -105,7 +107,7 @@ void UpdateCommitteeAction::setRemovedMembers(const CredentialSet& value) { const CredentialSet copy(value); - checkCardanoError(cardano_update_committee_action_set_members_to_be_removed(checked(), copy.checked()), "UpdateCommitteeAction setRemovedMembers"); + checkCardanoError(cardano_update_committee_action_set_members_to_be_removed(checked(), checkedNativeHandle(copy)), "UpdateCommitteeAction setRemovedMembers"); } CommitteeMembersMap @@ -119,7 +121,7 @@ UpdateCommitteeAction::addedMembers() const throw std::logic_error("UpdateCommitteeAction has no added members"); } - const CommitteeMembersMap found(owner.release()); + const CommitteeMembersMap found = CommitteeMembersMap::adopt(owner.release()); return CommitteeMembersMap(found); } @@ -127,7 +129,7 @@ void UpdateCommitteeAction::setAddedMembers(const CommitteeMembersMap& value) { const CommitteeMembersMap copy(value); - checkCardanoError(cardano_update_committee_action_set_members_to_be_added(checked(), copy.checked()), "UpdateCommitteeAction setAddedMembers"); + checkCardanoError(cardano_update_committee_action_set_members_to_be_added(checked(), checkedNativeHandle(copy)), "UpdateCommitteeAction setAddedMembers"); } UnitInterval @@ -141,7 +143,7 @@ UpdateCommitteeAction::quorum() const throw std::logic_error("UpdateCommitteeAction has no quorum"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -149,7 +151,7 @@ void UpdateCommitteeAction::setQuorum(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_update_committee_action_set_quorum(checked(), copy.checked()), "UpdateCommitteeAction setQuorum"); + checkCardanoError(cardano_update_committee_action_set_quorum(checked(), checkedNativeHandle(copy)), "UpdateCommitteeAction setQuorum"); } std::optional @@ -163,7 +165,7 @@ UpdateCommitteeAction::previousAction() const return std::nullopt; } - const GovernanceActionId found(owner.release()); + const GovernanceActionId found = GovernanceActionId::adopt(owner.release()); return GovernanceActionId(found); } @@ -171,7 +173,7 @@ void UpdateCommitteeAction::setPreviousAction(const std::optional& value) { const std::optional copy(value); - cardano_governance_action_id_t* data = copy ? copy->checked() : nullptr; + cardano_governance_action_id_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_update_committee_action_set_governance_action_id(checked(), data), "UpdateCommitteeAction setPreviousAction"); } @@ -227,6 +229,35 @@ UpdateCommitteeAction::operator!=(const UpdateCommitteeAction& other) const return !(*this == other); } +UpdateCommitteeAction +UpdateCommitteeAction::adopt(cardano_update_committee_action_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null UpdateCommitteeAction"); + } + + return UpdateCommitteeAction(value); +} + +cardano_update_committee_action_t* +UpdateCommitteeAction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_update_committee_action_t* +UpdateCommitteeAction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_update_committee_action_t* +UpdateCommitteeAction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ UpdateCommitteeAction::UpdateCommitteeAction(cardano_update_committee_action_t* value) noexcept diff --git a/lib/src/ProtocolParams/CostModel.cpp b/lib/src/ProtocolParams/CostModel.cpp index 1745e259..5f3b403f 100644 --- a/lib/src/ProtocolParams/CostModel.cpp +++ b/lib/src/ProtocolParams/CostModel.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -205,6 +207,35 @@ CostModel::operator!=(const CostModel& other) const return !(*this == other); } +CostModel +CostModel::adopt(cardano_cost_model_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CostModel"); + } + + return CostModel(value); +} + +cardano_cost_model_t* +CostModel::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_cost_model_t* +CostModel::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_cost_model_t* +CostModel::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ CostModel::CostModel(cardano_cost_model_t* value) noexcept diff --git a/lib/src/ProtocolParams/CostModels.cpp b/lib/src/ProtocolParams/CostModels.cpp index 7c7fa4b3..808e1b38 100644 --- a/lib/src/ProtocolParams/CostModels.cpp +++ b/lib/src/ProtocolParams/CostModels.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -86,7 +88,7 @@ void CostModels::insert(const CostModel& model) { const CostModel copy(model); - checkCardanoError(cardano_costmdls_insert(checked(), copy.checked()), "CostModels insert"); + checkCardanoError(cardano_costmdls_insert(checked(), checkedNativeHandle(copy)), "CostModels insert"); invalidateElements(); } @@ -116,7 +118,7 @@ CostModels::get(std::uint8_t languageId) const return std::nullopt; } - const CostModel borrowed(owner.release()); + const CostModel borrowed = CostModel::adopt(owner.release()); return CostModel(borrowed); } @@ -455,6 +457,60 @@ CostModels::empty() const return size() == 0; } +CostModels +CostModels::adopt(cardano_costmdls_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null CostModels"); + } + + return CostModels(value); +} + +cardano_costmdls_t* +CostModels::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_costmdls_t* +CostModels::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_costmdls_t* +CostModels::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ CostModels::CostModels(cardano_costmdls_t* value) noexcept diff --git a/lib/src/ProtocolParams/DRepVotingThresholds.cpp b/lib/src/ProtocolParams/DRepVotingThresholds.cpp index bc485e82..df04e687 100644 --- a/lib/src/ProtocolParams/DRepVotingThresholds.cpp +++ b/lib/src/ProtocolParams/DRepVotingThresholds.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -59,16 +61,16 @@ DRepVotingThresholds::DRepVotingThresholds( const UnitInterval treasuryWithdrawalCopy(treasuryWithdrawal); cardano_drep_voting_thresholds_t* value = nullptr; const cardano_error_t status = cardano_drep_voting_thresholds_new( - motionNoConfidenceCopy.checked(), - committeeNormalCopy.checked(), - committeeNoConfidenceCopy.checked(), - updateConstitutionCopy.checked(), - hardForkInitiationCopy.checked(), - ppNetworkGroupCopy.checked(), - ppEconomicGroupCopy.checked(), - ppTechnicalGroupCopy.checked(), - ppGovernanceGroupCopy.checked(), - treasuryWithdrawalCopy.checked(), + checkedNativeHandle(motionNoConfidenceCopy), + checkedNativeHandle(committeeNormalCopy), + checkedNativeHandle(committeeNoConfidenceCopy), + checkedNativeHandle(updateConstitutionCopy), + checkedNativeHandle(hardForkInitiationCopy), + checkedNativeHandle(ppNetworkGroupCopy), + checkedNativeHandle(ppEconomicGroupCopy), + checkedNativeHandle(ppTechnicalGroupCopy), + checkedNativeHandle(ppGovernanceGroupCopy), + checkedNativeHandle(treasuryWithdrawalCopy), &value); CardanoObject owner(value); @@ -117,7 +119,7 @@ DRepVotingThresholds::motionNoConfidence() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds motionNoConfidence"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -125,7 +127,7 @@ void DRepVotingThresholds::setMotionNoConfidence(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_motion_no_confidence(checked(), copy.checked()), "DRepVotingThresholds setMotionNoConfidence"); + checkCardanoError(cardano_drep_voting_thresholds_set_motion_no_confidence(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setMotionNoConfidence"); } UnitInterval @@ -136,7 +138,7 @@ DRepVotingThresholds::committeeNormal() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds committeeNormal"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -144,7 +146,7 @@ void DRepVotingThresholds::setCommitteeNormal(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_committee_normal(checked(), copy.checked()), "DRepVotingThresholds setCommitteeNormal"); + checkCardanoError(cardano_drep_voting_thresholds_set_committee_normal(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setCommitteeNormal"); } UnitInterval @@ -155,7 +157,7 @@ DRepVotingThresholds::committeeNoConfidence() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds committeeNoConfidence"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -163,7 +165,7 @@ void DRepVotingThresholds::setCommitteeNoConfidence(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_committee_no_confidence(checked(), copy.checked()), "DRepVotingThresholds setCommitteeNoConfidence"); + checkCardanoError(cardano_drep_voting_thresholds_set_committee_no_confidence(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setCommitteeNoConfidence"); } UnitInterval @@ -174,7 +176,7 @@ DRepVotingThresholds::updateConstitution() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds updateConstitution"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -182,7 +184,7 @@ void DRepVotingThresholds::setUpdateConstitution(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_update_constitution(checked(), copy.checked()), "DRepVotingThresholds setUpdateConstitution"); + checkCardanoError(cardano_drep_voting_thresholds_set_update_constitution(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setUpdateConstitution"); } UnitInterval @@ -193,7 +195,7 @@ DRepVotingThresholds::hardForkInitiation() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds hardForkInitiation"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -201,7 +203,7 @@ void DRepVotingThresholds::setHardForkInitiation(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_hard_fork_initiation(checked(), copy.checked()), "DRepVotingThresholds setHardForkInitiation"); + checkCardanoError(cardano_drep_voting_thresholds_set_hard_fork_initiation(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setHardForkInitiation"); } UnitInterval @@ -212,7 +214,7 @@ DRepVotingThresholds::ppNetworkGroup() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds ppNetworkGroup"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -220,7 +222,7 @@ void DRepVotingThresholds::setPpNetworkGroup(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_pp_network_group(checked(), copy.checked()), "DRepVotingThresholds setPpNetworkGroup"); + checkCardanoError(cardano_drep_voting_thresholds_set_pp_network_group(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setPpNetworkGroup"); } UnitInterval @@ -231,7 +233,7 @@ DRepVotingThresholds::ppEconomicGroup() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds ppEconomicGroup"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -239,7 +241,7 @@ void DRepVotingThresholds::setPpEconomicGroup(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_pp_economic_group(checked(), copy.checked()), "DRepVotingThresholds setPpEconomicGroup"); + checkCardanoError(cardano_drep_voting_thresholds_set_pp_economic_group(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setPpEconomicGroup"); } UnitInterval @@ -250,7 +252,7 @@ DRepVotingThresholds::ppTechnicalGroup() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds ppTechnicalGroup"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -258,7 +260,7 @@ void DRepVotingThresholds::setPpTechnicalGroup(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_pp_technical_group(checked(), copy.checked()), "DRepVotingThresholds setPpTechnicalGroup"); + checkCardanoError(cardano_drep_voting_thresholds_set_pp_technical_group(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setPpTechnicalGroup"); } UnitInterval @@ -269,7 +271,7 @@ DRepVotingThresholds::ppGovernanceGroup() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds ppGovernanceGroup"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -277,7 +279,7 @@ void DRepVotingThresholds::setPpGovernanceGroup(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_pp_governance_group(checked(), copy.checked()), "DRepVotingThresholds setPpGovernanceGroup"); + checkCardanoError(cardano_drep_voting_thresholds_set_pp_governance_group(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setPpGovernanceGroup"); } UnitInterval @@ -288,7 +290,7 @@ DRepVotingThresholds::treasuryWithdrawal() const CardanoObject owner(value); checkCardanoError(status, "DRepVotingThresholds treasuryWithdrawal"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -296,7 +298,7 @@ void DRepVotingThresholds::setTreasuryWithdrawal(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_drep_voting_thresholds_set_treasury_withdrawal(checked(), copy.checked()), "DRepVotingThresholds setTreasuryWithdrawal"); + checkCardanoError(cardano_drep_voting_thresholds_set_treasury_withdrawal(checked(), checkedNativeHandle(copy)), "DRepVotingThresholds setTreasuryWithdrawal"); } std::vector @@ -351,6 +353,35 @@ DRepVotingThresholds::operator!=(const DRepVotingThresholds& other) const return !(*this == other); } +DRepVotingThresholds +DRepVotingThresholds::adopt(cardano_drep_voting_thresholds_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null DRepVotingThresholds"); + } + + return DRepVotingThresholds(value); +} + +cardano_drep_voting_thresholds_t* +DRepVotingThresholds::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_drep_voting_thresholds_t* +DRepVotingThresholds::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_drep_voting_thresholds_t* +DRepVotingThresholds::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ DRepVotingThresholds::DRepVotingThresholds(cardano_drep_voting_thresholds_t* value) noexcept diff --git a/lib/src/ProtocolParams/ExUnitPrices.cpp b/lib/src/ProtocolParams/ExUnitPrices.cpp index d195d90e..2e48c418 100644 --- a/lib/src/ProtocolParams/ExUnitPrices.cpp +++ b/lib/src/ProtocolParams/ExUnitPrices.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ ExUnitPrices::ExUnitPrices(const UnitInterval& memoryPrice, const UnitInterval& const UnitInterval memoryCopy(memoryPrice); const UnitInterval stepsCopy(stepsPrice); cardano_ex_unit_prices_t* value = nullptr; - const cardano_error_t status = cardano_ex_unit_prices_new(memoryCopy.checked(), stepsCopy.checked(), &value); + const cardano_error_t status = cardano_ex_unit_prices_new(checkedNativeHandle(memoryCopy), checkedNativeHandle(stepsCopy), &value); CardanoObject owner(value); checkCardanoError(status, "ExUnitPrices"); @@ -88,7 +90,7 @@ ExUnitPrices::memoryPrice() const CardanoObject owner(value); checkCardanoError(status, "ExUnitPrices memoryPrice"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -100,7 +102,7 @@ ExUnitPrices::stepsPrice() const CardanoObject owner(value); checkCardanoError(status, "ExUnitPrices stepsPrice"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -108,14 +110,14 @@ void ExUnitPrices::setMemoryPrice(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_ex_unit_prices_set_memory_prices(checked(), copy.checked()), "ExUnitPrices setMemoryPrice"); + checkCardanoError(cardano_ex_unit_prices_set_memory_prices(checked(), checkedNativeHandle(copy)), "ExUnitPrices setMemoryPrice"); } void ExUnitPrices::setStepsPrice(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_ex_unit_prices_set_steps_prices(checked(), copy.checked()), "ExUnitPrices setStepsPrice"); + checkCardanoError(cardano_ex_unit_prices_set_steps_prices(checked(), checkedNativeHandle(copy)), "ExUnitPrices setStepsPrice"); } std::vector @@ -170,6 +172,35 @@ ExUnitPrices::operator!=(const ExUnitPrices& other) const return !(*this == other); } +ExUnitPrices +ExUnitPrices::adopt(cardano_ex_unit_prices_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ExUnitPrices"); + } + + return ExUnitPrices(value); +} + +cardano_ex_unit_prices_t* +ExUnitPrices::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_ex_unit_prices_t* +ExUnitPrices::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_ex_unit_prices_t* +ExUnitPrices::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ExUnitPrices::ExUnitPrices(cardano_ex_unit_prices_t* value) noexcept diff --git a/lib/src/ProtocolParams/PoolVotingThresholds.cpp b/lib/src/ProtocolParams/PoolVotingThresholds.cpp index 82319edf..3c2252fe 100644 --- a/lib/src/ProtocolParams/PoolVotingThresholds.cpp +++ b/lib/src/ProtocolParams/PoolVotingThresholds.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -49,11 +51,11 @@ PoolVotingThresholds::PoolVotingThresholds( const UnitInterval securityRelevantParamCopy(securityRelevantParam); cardano_pool_voting_thresholds_t* value = nullptr; const cardano_error_t status = cardano_pool_voting_thresholds_new( - motionNoConfidenceCopy.checked(), - committeeNormalCopy.checked(), - committeeNoConfidenceCopy.checked(), - hardForkInitiationCopy.checked(), - securityRelevantParamCopy.checked(), + checkedNativeHandle(motionNoConfidenceCopy), + checkedNativeHandle(committeeNormalCopy), + checkedNativeHandle(committeeNoConfidenceCopy), + checkedNativeHandle(hardForkInitiationCopy), + checkedNativeHandle(securityRelevantParamCopy), &value); CardanoObject owner(value); @@ -102,7 +104,7 @@ PoolVotingThresholds::motionNoConfidence() const CardanoObject owner(value); checkCardanoError(status, "PoolVotingThresholds motionNoConfidence"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -110,7 +112,7 @@ void PoolVotingThresholds::setMotionNoConfidence(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_voting_thresholds_set_motion_no_confidence(checked(), copy.checked()), "PoolVotingThresholds setMotionNoConfidence"); + checkCardanoError(cardano_pool_voting_thresholds_set_motion_no_confidence(checked(), checkedNativeHandle(copy)), "PoolVotingThresholds setMotionNoConfidence"); } UnitInterval @@ -121,7 +123,7 @@ PoolVotingThresholds::committeeNormal() const CardanoObject owner(value); checkCardanoError(status, "PoolVotingThresholds committeeNormal"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -129,7 +131,7 @@ void PoolVotingThresholds::setCommitteeNormal(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_voting_thresholds_set_committee_normal(checked(), copy.checked()), "PoolVotingThresholds setCommitteeNormal"); + checkCardanoError(cardano_pool_voting_thresholds_set_committee_normal(checked(), checkedNativeHandle(copy)), "PoolVotingThresholds setCommitteeNormal"); } UnitInterval @@ -140,7 +142,7 @@ PoolVotingThresholds::committeeNoConfidence() const CardanoObject owner(value); checkCardanoError(status, "PoolVotingThresholds committeeNoConfidence"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -148,7 +150,7 @@ void PoolVotingThresholds::setCommitteeNoConfidence(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_voting_thresholds_set_committee_no_confidence(checked(), copy.checked()), "PoolVotingThresholds setCommitteeNoConfidence"); + checkCardanoError(cardano_pool_voting_thresholds_set_committee_no_confidence(checked(), checkedNativeHandle(copy)), "PoolVotingThresholds setCommitteeNoConfidence"); } UnitInterval @@ -159,7 +161,7 @@ PoolVotingThresholds::hardForkInitiation() const CardanoObject owner(value); checkCardanoError(status, "PoolVotingThresholds hardForkInitiation"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -167,7 +169,7 @@ void PoolVotingThresholds::setHardForkInitiation(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_voting_thresholds_set_hard_fork_initiation(checked(), copy.checked()), "PoolVotingThresholds setHardForkInitiation"); + checkCardanoError(cardano_pool_voting_thresholds_set_hard_fork_initiation(checked(), checkedNativeHandle(copy)), "PoolVotingThresholds setHardForkInitiation"); } UnitInterval @@ -178,7 +180,7 @@ PoolVotingThresholds::securityRelevantParam() const CardanoObject owner(value); checkCardanoError(status, "PoolVotingThresholds securityRelevantParam"); - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -186,7 +188,7 @@ void PoolVotingThresholds::setSecurityRelevantParam(const UnitInterval& value) { const UnitInterval copy(value); - checkCardanoError(cardano_pool_voting_thresholds_set_security_relevant_param(checked(), copy.checked()), "PoolVotingThresholds setSecurityRelevantParam"); + checkCardanoError(cardano_pool_voting_thresholds_set_security_relevant_param(checked(), checkedNativeHandle(copy)), "PoolVotingThresholds setSecurityRelevantParam"); } std::vector @@ -241,6 +243,35 @@ PoolVotingThresholds::operator!=(const PoolVotingThresholds& other) const return !(*this == other); } +PoolVotingThresholds +PoolVotingThresholds::adopt(cardano_pool_voting_thresholds_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PoolVotingThresholds"); + } + + return PoolVotingThresholds(value); +} + +cardano_pool_voting_thresholds_t* +PoolVotingThresholds::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_pool_voting_thresholds_t* +PoolVotingThresholds::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_pool_voting_thresholds_t* +PoolVotingThresholds::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PoolVotingThresholds::PoolVotingThresholds(cardano_pool_voting_thresholds_t* value) noexcept diff --git a/lib/src/ProtocolParams/ProposedParamUpdates.cpp b/lib/src/ProtocolParams/ProposedParamUpdates.cpp index 33ba8eef..e8b06107 100644 --- a/lib/src/ProtocolParams/ProposedParamUpdates.cpp +++ b/lib/src/ProtocolParams/ProposedParamUpdates.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -89,14 +91,14 @@ ProposedParamUpdates::add(const Blake2bHash& key, const ProtocolParamUpdate& upd { const Blake2bHash keyCopy(key); const ProtocolParamUpdate updateCopy(update); - checkCardanoError(cardano_proposed_param_updates_insert(checked(), keyCopy.checked(), updateCopy.checked()), "ProposedParamUpdates add"); + checkCardanoError(cardano_proposed_param_updates_insert(checked(), checkedNativeHandle(keyCopy), checkedNativeHandle(updateCopy)), "ProposedParamUpdates add"); } std::optional ProposedParamUpdates::get(const Blake2bHash& key) const { cardano_protocol_param_update_t* value = nullptr; - const cardano_error_t status = cardano_proposed_param_updates_get(checked(), key.checked(), &value); + const cardano_error_t status = cardano_proposed_param_updates_get(checked(), checkedNativeHandle(key), &value); CardanoObject owner(value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -105,7 +107,7 @@ ProposedParamUpdates::get(const Blake2bHash& key) const } checkCardanoError(status, "ProposedParamUpdates get"); - const ProtocolParamUpdate found(owner.release()); + const ProtocolParamUpdate found = ProtocolParamUpdate::adopt(owner.release()); return ProtocolParamUpdate(found); } @@ -122,7 +124,7 @@ ProposedParamUpdates::keyAt(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "ProposedParamUpdates keyAt"); - const Blake2bHash found(owner.release()); + const Blake2bHash found = Blake2bHash::adopt(owner.release()); return Blake2bHash(found); } @@ -139,7 +141,7 @@ ProposedParamUpdates::valueAt(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "ProposedParamUpdates valueAt"); - const ProtocolParamUpdate found(owner.release()); + const ProtocolParamUpdate found = ProtocolParamUpdate::adopt(owner.release()); return ProtocolParamUpdate(found); } @@ -158,8 +160,8 @@ ProposedParamUpdates::at(std::size_t index) const CardanoObject updateOwner(update); checkCardanoError(status, "ProposedParamUpdates at"); - const Blake2bHash copiedKey(keyOwner.release()); - const ProtocolParamUpdate copiedUpdate(updateOwner.release()); + const Blake2bHash copiedKey = Blake2bHash::adopt(keyOwner.release()); + const ProtocolParamUpdate copiedUpdate = ProtocolParamUpdate::adopt(updateOwner.release()); return { Blake2bHash(copiedKey), ProtocolParamUpdate(copiedUpdate) }; } @@ -215,6 +217,35 @@ ProposedParamUpdates::operator!=(const ProposedParamUpdates& other) const return !(*this == other); } +ProposedParamUpdates +ProposedParamUpdates::adopt(cardano_proposed_param_updates_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProposedParamUpdates"); + } + + return ProposedParamUpdates(value); +} + +cardano_proposed_param_updates_t* +ProposedParamUpdates::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_proposed_param_updates_t* +ProposedParamUpdates::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_proposed_param_updates_t* +ProposedParamUpdates::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ProposedParamUpdates::ProposedParamUpdates(cardano_proposed_param_updates_t* value) noexcept diff --git a/lib/src/ProtocolParams/ProtocolParamUpdate.cpp b/lib/src/ProtocolParams/ProtocolParamUpdate.cpp index ed79ceef..f4386086 100644 --- a/lib/src/ProtocolParams/ProtocolParamUpdate.cpp +++ b/lib/src/ProtocolParams/ProtocolParamUpdate.cpp @@ -38,6 +38,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -303,7 +305,7 @@ ProtocolParamUpdate::poolPledgeInfluence() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -311,7 +313,7 @@ void ProtocolParamUpdate::setPoolPledgeInfluence(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_pool_pledge_influence(checked(), data), "ProtocolParamUpdate setPoolPledgeInfluence"); } @@ -334,7 +336,7 @@ ProtocolParamUpdate::expansionRate() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -342,7 +344,7 @@ void ProtocolParamUpdate::setExpansionRate(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_expansion_rate(checked(), data), "ProtocolParamUpdate setExpansionRate"); } @@ -365,7 +367,7 @@ ProtocolParamUpdate::treasuryGrowthRate() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -373,7 +375,7 @@ void ProtocolParamUpdate::setTreasuryGrowthRate(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_treasury_growth_rate(checked(), data), "ProtocolParamUpdate setTreasuryGrowthRate"); } @@ -396,7 +398,7 @@ ProtocolParamUpdate::d() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -404,7 +406,7 @@ void ProtocolParamUpdate::setD(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_d(checked(), data), "ProtocolParamUpdate setD"); } @@ -470,7 +472,7 @@ ProtocolParamUpdate::protocolVersion() const return std::nullopt; } - const ProtocolVersion result(owner.release()); + const ProtocolVersion result = ProtocolVersion::adopt(owner.release()); return ProtocolVersion(result); } @@ -478,7 +480,7 @@ void ProtocolParamUpdate::setProtocolVersion(const std::optional& value) { const std::optional copy(value); - cardano_protocol_version_t* data = copy ? copy->checked() : nullptr; + cardano_protocol_version_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_protocol_version(checked(), data), "ProtocolParamUpdate setProtocolVersion"); } @@ -545,7 +547,7 @@ ProtocolParamUpdate::costModels() const return std::nullopt; } - const CostModels result(owner.release()); + const CostModels result = CostModels::adopt(owner.release()); return CostModels(result); } @@ -553,7 +555,7 @@ void ProtocolParamUpdate::setCostModels(const std::optional& value) { const std::optional copy(value); - cardano_costmdls_t* data = copy ? copy->checked() : nullptr; + cardano_costmdls_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_cost_models(checked(), data), "ProtocolParamUpdate setCostModels"); } @@ -576,7 +578,7 @@ ProtocolParamUpdate::executionCosts() const return std::nullopt; } - const ExUnitPrices result(owner.release()); + const ExUnitPrices result = ExUnitPrices::adopt(owner.release()); return ExUnitPrices(result); } @@ -584,7 +586,7 @@ void ProtocolParamUpdate::setExecutionCosts(const std::optional& value) { const std::optional copy(value); - cardano_ex_unit_prices_t* data = copy ? copy->checked() : nullptr; + cardano_ex_unit_prices_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_execution_costs(checked(), data), "ProtocolParamUpdate setExecutionCosts"); } @@ -607,7 +609,7 @@ ProtocolParamUpdate::maxTxExUnits() const return std::nullopt; } - const ExUnits result(owner.release()); + const ExUnits result = ExUnits::adopt(owner.release()); return ExUnits(result); } @@ -615,7 +617,7 @@ void ProtocolParamUpdate::setMaxTxExUnits(const std::optional& value) { const std::optional copy(value); - cardano_ex_units_t* data = copy ? copy->checked() : nullptr; + cardano_ex_units_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_max_tx_ex_units(checked(), data), "ProtocolParamUpdate setMaxTxExUnits"); } @@ -638,7 +640,7 @@ ProtocolParamUpdate::maxBlockExUnits() const return std::nullopt; } - const ExUnits result(owner.release()); + const ExUnits result = ExUnits::adopt(owner.release()); return ExUnits(result); } @@ -646,7 +648,7 @@ void ProtocolParamUpdate::setMaxBlockExUnits(const std::optional& value) { const std::optional copy(value); - cardano_ex_units_t* data = copy ? copy->checked() : nullptr; + cardano_ex_units_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_max_block_ex_units(checked(), data), "ProtocolParamUpdate setMaxBlockExUnits"); } @@ -735,7 +737,7 @@ ProtocolParamUpdate::poolVotingThresholds() const return std::nullopt; } - const PoolVotingThresholds result(owner.release()); + const PoolVotingThresholds result = PoolVotingThresholds::adopt(owner.release()); return PoolVotingThresholds(result); } @@ -743,7 +745,7 @@ void ProtocolParamUpdate::setPoolVotingThresholds(const std::optional& value) { const std::optional copy(value); - cardano_pool_voting_thresholds_t* data = copy ? copy->checked() : nullptr; + cardano_pool_voting_thresholds_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_pool_voting_thresholds(checked(), data), "ProtocolParamUpdate setPoolVotingThresholds"); } @@ -766,7 +768,7 @@ ProtocolParamUpdate::drepVotingThresholds() const return std::nullopt; } - const DRepVotingThresholds result(owner.release()); + const DRepVotingThresholds result = DRepVotingThresholds::adopt(owner.release()); return DRepVotingThresholds(result); } @@ -774,7 +776,7 @@ void ProtocolParamUpdate::setDrepVotingThresholds(const std::optional& value) { const std::optional copy(value); - cardano_drep_voting_thresholds_t* data = copy ? copy->checked() : nullptr; + cardano_drep_voting_thresholds_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_drep_voting_thresholds(checked(), data), "ProtocolParamUpdate setDrepVotingThresholds"); } @@ -929,7 +931,7 @@ ProtocolParamUpdate::refScriptCostPerByte() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -937,7 +939,7 @@ void ProtocolParamUpdate::setRefScriptCostPerByte(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_ref_script_cost_per_byte(checked(), data), "ProtocolParamUpdate setRefScriptCostPerByte"); } @@ -1026,7 +1028,7 @@ ProtocolParamUpdate::refScriptCostMultiplier() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1034,7 +1036,7 @@ void ProtocolParamUpdate::setRefScriptCostMultiplier(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_ref_script_cost_multiplier(checked(), data), "ProtocolParamUpdate setRefScriptCostMultiplier"); } @@ -1057,7 +1059,7 @@ ProtocolParamUpdate::maxPledgeLeverage() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1065,7 +1067,7 @@ void ProtocolParamUpdate::setMaxPledgeLeverage(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_max_pledge_leverage(checked(), data), "ProtocolParamUpdate setMaxPledgeLeverage"); } @@ -1088,7 +1090,7 @@ ProtocolParamUpdate::minPoolMargin() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1096,7 +1098,7 @@ void ProtocolParamUpdate::setMinPoolMargin(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_min_pool_margin(checked(), data), "ProtocolParamUpdate setMinPoolMargin"); } @@ -1207,7 +1209,7 @@ ProtocolParamUpdate::leiosQuorumStakeThreshold() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1215,7 +1217,7 @@ void ProtocolParamUpdate::setLeiosQuorumStakeThreshold(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_leios_quorum_stake_threshold(checked(), data), "ProtocolParamUpdate setLeiosQuorumStakeThreshold"); } @@ -1282,7 +1284,7 @@ ProtocolParamUpdate::maxEndorserBlockExecutionUnits() const return std::nullopt; } - const ExUnits result(owner.release()); + const ExUnits result = ExUnits::adopt(owner.release()); return ExUnits(result); } @@ -1290,7 +1292,7 @@ void ProtocolParamUpdate::setMaxEndorserBlockExecutionUnits(const std::optional& value) { const std::optional copy(value); - cardano_ex_units_t* data = copy ? copy->checked() : nullptr; + cardano_ex_units_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_max_endorser_block_execution_units(checked(), data), "ProtocolParamUpdate setMaxEndorserBlockExecutionUnits"); } @@ -1357,7 +1359,7 @@ ProtocolParamUpdate::perasHealingFactor() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1365,7 +1367,7 @@ void ProtocolParamUpdate::setPerasHealingFactor(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_peras_healing_factor(checked(), data), "ProtocolParamUpdate setPerasHealingFactor"); } @@ -1454,7 +1456,7 @@ ProtocolParamUpdate::perasQuorumThresholdSafetyMargin() const return std::nullopt; } - const UnitInterval result(owner.release()); + const UnitInterval result = UnitInterval::adopt(owner.release()); return UnitInterval(result); } @@ -1462,7 +1464,7 @@ void ProtocolParamUpdate::setPerasQuorumThresholdSafetyMargin(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_param_update_set_peras_quorum_threshold_safety_margin(checked(), data), "ProtocolParamUpdate setPerasQuorumThresholdSafetyMargin"); } @@ -1572,7 +1574,7 @@ ProtocolParamUpdate::toPlutusData() const CardanoObject owner(value); checkCardanoError(status, "ProtocolParamUpdate toPlutusData"); - return PlutusData(*owner.release()); + return PlutusData::adopt(owner.release()); } std::string @@ -1621,6 +1623,35 @@ ProtocolParamUpdate::operator!=(const ProtocolParamUpdate& other) const return !(*this == other); } +ProtocolParamUpdate +ProtocolParamUpdate::adopt(cardano_protocol_param_update_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProtocolParamUpdate"); + } + + return ProtocolParamUpdate(value); +} + +cardano_protocol_param_update_t* +ProtocolParamUpdate::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_protocol_param_update_t* +ProtocolParamUpdate::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_protocol_param_update_t* +ProtocolParamUpdate::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ProtocolParamUpdate::ProtocolParamUpdate(cardano_protocol_param_update_t* value) noexcept diff --git a/lib/src/ProtocolParams/ProtocolParameters.cpp b/lib/src/ProtocolParams/ProtocolParameters.cpp index 5ebc84b1..418f1089 100644 --- a/lib/src/ProtocolParams/ProtocolParameters.cpp +++ b/lib/src/ProtocolParams/ProtocolParameters.cpp @@ -33,6 +33,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -188,7 +190,7 @@ ProtocolParameters::poolPledgeInfluence() const throw std::logic_error("ProtocolParameters poolPledgeInfluence is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -196,7 +198,7 @@ void ProtocolParameters::setPoolPledgeInfluence(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_pool_pledge_influence(checked(), data), "ProtocolParameters setPoolPledgeInfluence"); } @@ -211,7 +213,7 @@ ProtocolParameters::expansionRate() const throw std::logic_error("ProtocolParameters expansionRate is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -219,7 +221,7 @@ void ProtocolParameters::setExpansionRate(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_expansion_rate(checked(), data), "ProtocolParameters setExpansionRate"); } @@ -234,7 +236,7 @@ ProtocolParameters::treasuryGrowthRate() const throw std::logic_error("ProtocolParameters treasuryGrowthRate is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -242,7 +244,7 @@ void ProtocolParameters::setTreasuryGrowthRate(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_treasury_growth_rate(checked(), data), "ProtocolParameters setTreasuryGrowthRate"); } @@ -257,7 +259,7 @@ ProtocolParameters::d() const throw std::logic_error("ProtocolParameters d is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -265,7 +267,7 @@ void ProtocolParameters::setD(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_d(checked(), data), "ProtocolParameters setD"); } @@ -317,7 +319,7 @@ ProtocolParameters::protocolVersion() const throw std::logic_error("ProtocolParameters protocolVersion is unavailable"); } - const ProtocolVersion found(owner.release()); + const ProtocolVersion found = ProtocolVersion::adopt(owner.release()); return ProtocolVersion(found); } @@ -325,7 +327,7 @@ void ProtocolParameters::setProtocolVersion(const ProtocolVersion& value) { const ProtocolVersion copy(value); - cardano_protocol_version_t* data = copy.checked(); + cardano_protocol_version_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_protocol_version(checked(), data), "ProtocolParameters setProtocolVersion"); } @@ -364,7 +366,7 @@ ProtocolParameters::costModels() const throw std::logic_error("ProtocolParameters costModels is unavailable"); } - const CostModels found(owner.release()); + const CostModels found = CostModels::adopt(owner.release()); return CostModels(found); } @@ -372,7 +374,7 @@ void ProtocolParameters::setCostModels(const CostModels& value) { const CostModels copy(value); - cardano_costmdls_t* data = copy.checked(); + cardano_costmdls_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_cost_models(checked(), data), "ProtocolParameters setCostModels"); } @@ -387,7 +389,7 @@ ProtocolParameters::executionCosts() const throw std::logic_error("ProtocolParameters executionCosts is unavailable"); } - const ExUnitPrices found(owner.release()); + const ExUnitPrices found = ExUnitPrices::adopt(owner.release()); return ExUnitPrices(found); } @@ -395,7 +397,7 @@ void ProtocolParameters::setExecutionCosts(const ExUnitPrices& value) { const ExUnitPrices copy(value); - cardano_ex_unit_prices_t* data = copy.checked(); + cardano_ex_unit_prices_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_execution_costs(checked(), data), "ProtocolParameters setExecutionCosts"); } @@ -410,7 +412,7 @@ ProtocolParameters::maxTxExUnits() const throw std::logic_error("ProtocolParameters maxTxExUnits is unavailable"); } - const ExUnits found(owner.release()); + const ExUnits found = ExUnits::adopt(owner.release()); return ExUnits(found); } @@ -418,7 +420,7 @@ void ProtocolParameters::setMaxTxExUnits(const ExUnits& value) { const ExUnits copy(value); - cardano_ex_units_t* data = copy.checked(); + cardano_ex_units_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_max_tx_ex_units(checked(), data), "ProtocolParameters setMaxTxExUnits"); } @@ -433,7 +435,7 @@ ProtocolParameters::maxBlockExUnits() const throw std::logic_error("ProtocolParameters maxBlockExUnits is unavailable"); } - const ExUnits found(owner.release()); + const ExUnits found = ExUnits::adopt(owner.release()); return ExUnits(found); } @@ -441,7 +443,7 @@ void ProtocolParameters::setMaxBlockExUnits(const ExUnits& value) { const ExUnits copy(value); - cardano_ex_units_t* data = copy.checked(); + cardano_ex_units_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_max_block_ex_units(checked(), data), "ProtocolParameters setMaxBlockExUnits"); } @@ -497,7 +499,7 @@ ProtocolParameters::poolVotingThresholds() const throw std::logic_error("ProtocolParameters poolVotingThresholds is unavailable"); } - const PoolVotingThresholds found(owner.release()); + const PoolVotingThresholds found = PoolVotingThresholds::adopt(owner.release()); return PoolVotingThresholds(found); } @@ -505,7 +507,7 @@ void ProtocolParameters::setPoolVotingThresholds(const PoolVotingThresholds& value) { const PoolVotingThresholds copy(value); - cardano_pool_voting_thresholds_t* data = copy.checked(); + cardano_pool_voting_thresholds_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_pool_voting_thresholds(checked(), data), "ProtocolParameters setPoolVotingThresholds"); } @@ -520,7 +522,7 @@ ProtocolParameters::drepVotingThresholds() const throw std::logic_error("ProtocolParameters drepVotingThresholds is unavailable"); } - const DRepVotingThresholds found(owner.release()); + const DRepVotingThresholds found = DRepVotingThresholds::adopt(owner.release()); return DRepVotingThresholds(found); } @@ -528,7 +530,7 @@ void ProtocolParameters::setDrepVotingThresholds(const DRepVotingThresholds& value) { const DRepVotingThresholds copy(value); - cardano_drep_voting_thresholds_t* data = copy.checked(); + cardano_drep_voting_thresholds_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_drep_voting_thresholds(checked(), data), "ProtocolParameters setDrepVotingThresholds"); } @@ -615,7 +617,7 @@ ProtocolParameters::refScriptCostPerByte() const throw std::logic_error("ProtocolParameters refScriptCostPerByte is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -623,7 +625,7 @@ void ProtocolParameters::setRefScriptCostPerByte(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_ref_script_cost_per_byte(checked(), data), "ProtocolParameters setRefScriptCostPerByte"); } @@ -674,7 +676,7 @@ ProtocolParameters::refScriptCostMultiplier() const return std::nullopt; } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -682,7 +684,7 @@ void ProtocolParameters::setRefScriptCostMultiplier(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_parameters_set_ref_script_cost_multiplier(checked(), data), "ProtocolParameters setRefScriptCostMultiplier"); } @@ -697,7 +699,7 @@ ProtocolParameters::maxPledgeLeverage() const return std::nullopt; } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -705,7 +707,7 @@ void ProtocolParameters::setMaxPledgeLeverage(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_parameters_set_max_pledge_leverage(checked(), data), "ProtocolParameters setMaxPledgeLeverage"); } @@ -720,7 +722,7 @@ ProtocolParameters::minPoolMargin() const throw std::logic_error("ProtocolParameters minPoolMargin is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -728,7 +730,7 @@ void ProtocolParameters::setMinPoolMargin(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_min_pool_margin(checked(), data), "ProtocolParameters setMinPoolMargin"); } @@ -791,7 +793,7 @@ ProtocolParameters::leiosQuorumStakeThreshold() const throw std::logic_error("ProtocolParameters leiosQuorumStakeThreshold is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -799,7 +801,7 @@ void ProtocolParameters::setLeiosQuorumStakeThreshold(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_leios_quorum_stake_threshold(checked(), data), "ProtocolParameters setLeiosQuorumStakeThreshold"); } @@ -838,7 +840,7 @@ ProtocolParameters::maxEndorserBlockExecutionUnits() const throw std::logic_error("ProtocolParameters maxEndorserBlockExecutionUnits is unavailable"); } - const ExUnits found(owner.release()); + const ExUnits found = ExUnits::adopt(owner.release()); return ExUnits(found); } @@ -846,7 +848,7 @@ void ProtocolParameters::setMaxEndorserBlockExecutionUnits(const ExUnits& value) { const ExUnits copy(value); - cardano_ex_units_t* data = copy.checked(); + cardano_ex_units_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_max_endorser_block_execution_units(checked(), data), "ProtocolParameters setMaxEndorserBlockExecutionUnits"); } @@ -885,7 +887,7 @@ ProtocolParameters::perasHealingFactor() const return std::nullopt; } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -893,7 +895,7 @@ void ProtocolParameters::setPerasHealingFactor(const std::optional& value) { const std::optional copy(value); - cardano_unit_interval_t* data = copy ? copy->checked() : nullptr; + cardano_unit_interval_t* data = copy ? checkedNativeHandle(*copy) : nullptr; checkCardanoError(cardano_protocol_parameters_set_peras_healing_factor(checked(), data), "ProtocolParameters setPerasHealingFactor"); } @@ -946,7 +948,7 @@ ProtocolParameters::perasQuorumThresholdSafetyMargin() const throw std::logic_error("ProtocolParameters perasQuorumThresholdSafetyMargin is unavailable"); } - const UnitInterval found(owner.release()); + const UnitInterval found = UnitInterval::adopt(owner.release()); return UnitInterval(found); } @@ -954,7 +956,7 @@ void ProtocolParameters::setPerasQuorumThresholdSafetyMargin(const UnitInterval& value) { const UnitInterval copy(value); - cardano_unit_interval_t* data = copy.checked(); + cardano_unit_interval_t* data = checkedNativeHandle(copy); checkCardanoError(cardano_protocol_parameters_set_peras_quorum_threshold_safety_margin(checked(), data), "ProtocolParameters setPerasQuorumThresholdSafetyMargin"); } @@ -1302,8 +1304,42 @@ ProtocolParameters::operator!=(const ProtocolParameters& other) const return !(*this == other); } +ProtocolParameters +ProtocolParameters::adopt(cardano_protocol_parameters_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ProtocolParameters"); + } + + return ProtocolParameters(value); +} + +cardano_protocol_parameters_t* +ProtocolParameters::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_protocol_parameters_t* +ProtocolParameters::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_protocol_parameters_t* +ProtocolParameters::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ +ProtocolParameters::ProtocolParameters(cardano_protocol_parameters_t* value) noexcept +: m_value(value) +{ +} + cardano_protocol_parameters_t* ProtocolParameters::checked() const { @@ -1320,7 +1356,7 @@ cardano_protocol_parameters_t* copyProtocolParametersToNative(const ProtocolParameters& parameters) { cardano_protocol_parameters_t* value = nullptr; - const cardano_error_t status = cardano_protocol_parameters_deep_clone(parameters.checked(), &value); + const cardano_error_t status = cardano_protocol_parameters_deep_clone(checkedNativeHandle(parameters), &value); CardanoObject owner(value); checkCardanoError(status, "Copy protocol parameters to native"); @@ -1331,17 +1367,12 @@ copyProtocolParametersToNative(const ProtocolParameters& parameters) ProtocolParameters copyProtocolParametersFromNative(const cardano_protocol_parameters_t* parameters) { - ProtocolParameters result; - cardano_protocol_parameters_t* value = nullptr; const cardano_error_t status = cardano_protocol_parameters_deep_clone(parameters, &value); CardanoObject owner(value); checkCardanoError(status, "Copy protocol parameters from native"); - cardano_protocol_parameters_unref(&result.m_value); - result.m_value = owner.release(); - - return result; + return ProtocolParameters::adopt(owner.release()); } void diff --git a/lib/src/ProtocolParams/Update.cpp b/lib/src/ProtocolParams/Update.cpp index 19ca9a9a..44d41f11 100644 --- a/lib/src/ProtocolParams/Update.cpp +++ b/lib/src/ProtocolParams/Update.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -38,7 +40,7 @@ Update::Update(std::uint64_t epoch, const ProposedParamUpdates& proposals) { const ProposedParamUpdates copy(proposals); cardano_update_t* value = nullptr; - const cardano_error_t status = cardano_update_new(epoch, copy.checked(), &value); + const cardano_error_t status = cardano_update_new(epoch, checkedNativeHandle(copy), &value); CardanoObject owner(value); checkCardanoError(status, "Update"); @@ -104,7 +106,7 @@ Update::proposals() const CardanoObject owner(clone); checkCardanoError(status, "Update proposals copy"); - return ProposedParamUpdates(owner.release()); + return ProposedParamUpdates::adopt(owner.release()); } void @@ -117,7 +119,7 @@ void Update::setProposals(const ProposedParamUpdates& value) { const ProposedParamUpdates copy(value); - checkCardanoError(cardano_update_set_proposed_parameters(checked(), copy.checked()), "Update setProposals"); + checkCardanoError(cardano_update_set_proposed_parameters(checked(), checkedNativeHandle(copy)), "Update setProposals"); } std::vector @@ -172,6 +174,35 @@ Update::operator!=(const Update& other) const return !(*this == other); } +Update +Update::adopt(cardano_update_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Update"); + } + + return Update(value); +} + +cardano_update_t* +Update::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_update_t* +Update::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_update_t* +Update::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Update::Update(cardano_update_t* value) noexcept diff --git a/lib/src/Scripts/NativeScripts/NativeScript.cpp b/lib/src/Scripts/NativeScripts/NativeScript.cpp index 56285a4e..443a189f 100644 --- a/lib/src/Scripts/NativeScripts/NativeScript.cpp +++ b/lib/src/Scripts/NativeScripts/NativeScript.cpp @@ -26,6 +26,7 @@ #include #include "../../CardanoInterop.h" +#include "../../ValueValidation.h" #include #include #include @@ -57,7 +58,7 @@ NativeScript::NativeScript(const ScriptPubkey& script) ScriptPubkey copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_pubkey(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_pubkey(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -70,7 +71,7 @@ NativeScript::NativeScript(ScriptPubkey&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_pubkey(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_pubkey(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -87,7 +88,7 @@ NativeScript::NativeScript(const ScriptAll& script) ScriptAll copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_all(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_all(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -100,7 +101,7 @@ NativeScript::NativeScript(ScriptAll&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_all(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_all(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -117,7 +118,7 @@ NativeScript::NativeScript(const ScriptAny& script) ScriptAny copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_any(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_any(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -130,7 +131,7 @@ NativeScript::NativeScript(ScriptAny&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_any(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_any(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -147,7 +148,7 @@ NativeScript::NativeScript(const ScriptNOfK& script) ScriptNOfK copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_n_of_k(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_n_of_k(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -160,7 +161,7 @@ NativeScript::NativeScript(ScriptNOfK&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_n_of_k(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_n_of_k(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -177,7 +178,7 @@ NativeScript::NativeScript(const ScriptInvalidBefore& script) ScriptInvalidBefore copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_invalid_before(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_invalid_before(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -190,7 +191,7 @@ NativeScript::NativeScript(ScriptInvalidBefore&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_invalid_before(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_invalid_before(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -207,7 +208,7 @@ NativeScript::NativeScript(const ScriptInvalidAfter& script) ScriptInvalidAfter copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_invalid_after(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_invalid_after(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -220,7 +221,7 @@ NativeScript::NativeScript(ScriptInvalidAfter&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_invalid_after(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_invalid_after(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -237,7 +238,7 @@ NativeScript::NativeScript(const ScriptRequireGuard& script) ScriptRequireGuard copy(script); cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_require_guard(copy.checked(), &value); + const cardano_error_t result = cardano_native_script_new_require_guard(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -250,7 +251,7 @@ NativeScript::NativeScript(ScriptRequireGuard&& script) : m_value(nullptr) { cardano_native_script_t* value = nullptr; - const cardano_error_t result = cardano_native_script_new_require_guard(script.checked(), &value); + const cardano_error_t result = cardano_native_script_new_require_guard(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -289,7 +290,7 @@ NativeScript::fromCbor(const std::vector& cbor) { NativeScript value(*decodeCbor(cbor, cardano_native_script_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -364,7 +365,7 @@ NativeScript::asPubkey() const checkCardanoError(result, "NativeScript asPubkey"); - const ScriptPubkey script(*owner.release()); + const ScriptPubkey script = ScriptPubkey::adopt(owner.release()); return ScriptPubkey(script); } @@ -379,7 +380,7 @@ NativeScript::asAll() const checkCardanoError(result, "NativeScript asAll"); - const ScriptAll script(*owner.release()); + const ScriptAll script = ScriptAll::adopt(owner.release()); return ScriptAll(script); } @@ -394,7 +395,7 @@ NativeScript::asAny() const checkCardanoError(result, "NativeScript asAny"); - const ScriptAny script(*owner.release()); + const ScriptAny script = ScriptAny::adopt(owner.release()); return ScriptAny(script); } @@ -409,7 +410,7 @@ NativeScript::asNOfK() const checkCardanoError(result, "NativeScript asNOfK"); - const ScriptNOfK script(*owner.release()); + const ScriptNOfK script = ScriptNOfK::adopt(owner.release()); return ScriptNOfK(script); } @@ -424,7 +425,7 @@ NativeScript::asInvalidBefore() const checkCardanoError(result, "NativeScript asInvalidBefore"); - const ScriptInvalidBefore script(*owner.release()); + const ScriptInvalidBefore script = ScriptInvalidBefore::adopt(owner.release()); return ScriptInvalidBefore(script); } @@ -439,7 +440,7 @@ NativeScript::asInvalidAfter() const checkCardanoError(result, "NativeScript asInvalidAfter"); - const ScriptInvalidAfter script(*owner.release()); + const ScriptInvalidAfter script = ScriptInvalidAfter::adopt(owner.release()); return ScriptInvalidAfter(script); } @@ -454,7 +455,7 @@ NativeScript::asRequireGuard() const checkCardanoError(result, "NativeScript asRequireGuard"); - const ScriptRequireGuard script(*owner.release()); + const ScriptRequireGuard script = ScriptRequireGuard::adopt(owner.release()); return ScriptRequireGuard(script); } @@ -529,6 +530,35 @@ NativeScript::operator!=(const NativeScript& other) const return !(*this == other); } +NativeScript +NativeScript::adopt(cardano_native_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null NativeScript"); + } + + return NativeScript(*value); +} + +cardano_native_script_t* +NativeScript::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_native_script_t* +NativeScript::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_native_script_t* +NativeScript::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ NativeScript::NativeScript(cardano_native_script_t& value) noexcept @@ -548,24 +578,24 @@ NativeScript::checked() const } void -NativeScript::validate() const +validateValue(const NativeScript& value) { - switch (type()) + switch (value.type()) { case NativeScriptType::RequirePubkey: - if (asPubkey().keyHash().toBytes().size() != 28U) + if (value.asPubkey().keyHash().toBytes().size() != 28U) { throw std::invalid_argument("Script key hash must be 28 bytes"); } break; case NativeScriptType::RequireAllOf: - asAll().scripts().validate(); + validateValue(value.asAll().scripts()); break; case NativeScriptType::RequireAnyOf: - asAny().scripts().validate(); + validateValue(value.asAny().scripts()); break; case NativeScriptType::RequireNOfK: - asNOfK().scripts().validate(); + validateValue(value.asNOfK().scripts()); break; case NativeScriptType::InvalidBefore: case NativeScriptType::InvalidAfter: diff --git a/lib/src/Scripts/NativeScripts/NativeScriptList.cpp b/lib/src/Scripts/NativeScripts/NativeScriptList.cpp index 5e485050..8e60048d 100644 --- a/lib/src/Scripts/NativeScripts/NativeScriptList.cpp +++ b/lib/src/Scripts/NativeScripts/NativeScriptList.cpp @@ -26,6 +26,7 @@ #include #include "../../CardanoInterop.h" +#include "../../ValueValidation.h" #include #include @@ -36,6 +37,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -94,7 +97,7 @@ NativeScriptList::fromCbor(const std::vector& cbor) { NativeScriptList value(*decodeCbor(cbor, cardano_native_script_list_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -152,7 +155,7 @@ NativeScriptList::pushBack(const NativeScript& script) NativeScript copy(script); - checkCardanoError(cardano_native_script_list_add(checked(), copy.checked()), "NativeScriptList pushBack"); + checkCardanoError(cardano_native_script_list_add(checked(), checkedNativeHandle(copy)), "NativeScriptList pushBack"); } std::vector @@ -507,6 +510,60 @@ NativeScriptList::erase(const_iterator first, const_iterator last) return m_elements.erase(first, last); } +NativeScriptList +NativeScriptList::adopt(cardano_native_script_list_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null NativeScriptList"); + } + + return NativeScriptList(*value); +} + +cardano_native_script_list_t* +NativeScriptList::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_native_script_list_t* +NativeScriptList::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_native_script_list_t* +NativeScriptList::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ NativeScriptList::NativeScriptList(cardano_native_script_list_t& value) noexcept @@ -528,13 +585,13 @@ NativeScriptList::checked() const } void -NativeScriptList::validate() const +validateValue(const NativeScriptList& value) { - const std::size_t count = size(); + const std::size_t count = value.size(); for (std::size_t index = 0U; index < count; ++index) { - at(index).validate(); + validateValue(value.at(index)); } } @@ -614,7 +671,7 @@ NativeScriptList::copyElement(std::size_t index) const checkCardanoError(result, "NativeScriptList at"); - const NativeScript script(*owner.release()); + const NativeScript script = NativeScript::adopt(owner.release()); return NativeScript(script); } diff --git a/lib/src/Scripts/NativeScripts/ScriptAll.cpp b/lib/src/Scripts/NativeScripts/ScriptAll.cpp index 22fe89d8..ae0ce5e1 100644 --- a/lib/src/Scripts/NativeScripts/ScriptAll.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptAll.cpp @@ -26,12 +26,15 @@ #include #include "../../CardanoInterop.h" +#include "../../ValueValidation.h" #include #include #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,7 +45,7 @@ ScriptAll::ScriptAll(const NativeScriptList& scripts) NativeScriptList copy(scripts); cardano_script_all_t* value = nullptr; - const cardano_error_t result = cardano_script_all_new(copy.checked(), &value); + const cardano_error_t result = cardano_script_all_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -79,7 +82,7 @@ ScriptAll::fromCbor(const std::vector& cbor) { ScriptAll value(*decodeCbor(cbor, cardano_script_all_from_cbor)); - value.scripts().validate(); + validateValue(value.scripts()); return value; } @@ -119,7 +122,7 @@ ScriptAll::scripts() const checkCardanoError(result, "ScriptAll scripts"); - const NativeScriptList list(*owner.release()); + const NativeScriptList list = NativeScriptList::adopt(owner.release()); return NativeScriptList(list); } @@ -129,7 +132,7 @@ ScriptAll::setScripts(const NativeScriptList& scripts) { NativeScriptList copy(scripts); - checkCardanoError(cardano_script_all_set_scripts(checked(), copy.checked()), "ScriptAll setScripts"); + checkCardanoError(cardano_script_all_set_scripts(checked(), checkedNativeHandle(copy)), "ScriptAll setScripts"); } std::vector @@ -193,6 +196,35 @@ ScriptAll::operator!=(const ScriptAll& other) const return !(*this == other); } +ScriptAll +ScriptAll::adopt(cardano_script_all_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptAll"); + } + + return ScriptAll(*value); +} + +cardano_script_all_t* +ScriptAll::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_all_t* +ScriptAll::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_all_t* +ScriptAll::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptAll::ScriptAll(cardano_script_all_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptAny.cpp b/lib/src/Scripts/NativeScripts/ScriptAny.cpp index e4ea7e08..18810c81 100644 --- a/lib/src/Scripts/NativeScripts/ScriptAny.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptAny.cpp @@ -26,12 +26,15 @@ #include #include "../../CardanoInterop.h" +#include "../../ValueValidation.h" #include #include #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,7 +45,7 @@ ScriptAny::ScriptAny(const NativeScriptList& scripts) NativeScriptList copy(scripts); cardano_script_any_t* value = nullptr; - const cardano_error_t result = cardano_script_any_new(copy.checked(), &value); + const cardano_error_t result = cardano_script_any_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -79,7 +82,7 @@ ScriptAny::fromCbor(const std::vector& cbor) { ScriptAny value(*decodeCbor(cbor, cardano_script_any_from_cbor)); - value.scripts().validate(); + validateValue(value.scripts()); return value; } @@ -119,7 +122,7 @@ ScriptAny::scripts() const checkCardanoError(result, "ScriptAny scripts"); - const NativeScriptList list(*owner.release()); + const NativeScriptList list = NativeScriptList::adopt(owner.release()); return NativeScriptList(list); } @@ -129,7 +132,7 @@ ScriptAny::setScripts(const NativeScriptList& scripts) { NativeScriptList copy(scripts); - checkCardanoError(cardano_script_any_set_scripts(checked(), copy.checked()), "ScriptAny setScripts"); + checkCardanoError(cardano_script_any_set_scripts(checked(), checkedNativeHandle(copy)), "ScriptAny setScripts"); } std::vector @@ -193,6 +196,35 @@ ScriptAny::operator!=(const ScriptAny& other) const return !(*this == other); } +ScriptAny +ScriptAny::adopt(cardano_script_any_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptAny"); + } + + return ScriptAny(*value); +} + +cardano_script_any_t* +ScriptAny::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_any_t* +ScriptAny::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_any_t* +ScriptAny::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptAny::ScriptAny(cardano_script_any_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptInvalidAfter.cpp b/lib/src/Scripts/NativeScripts/ScriptInvalidAfter.cpp index 1983581e..12d6568e 100644 --- a/lib/src/Scripts/NativeScripts/ScriptInvalidAfter.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptInvalidAfter.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -174,6 +176,35 @@ ScriptInvalidAfter::operator!=(const ScriptInvalidAfter& other) const return !(*this == other); } +ScriptInvalidAfter +ScriptInvalidAfter::adopt(cardano_script_invalid_after_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptInvalidAfter"); + } + + return ScriptInvalidAfter(*value); +} + +cardano_script_invalid_after_t* +ScriptInvalidAfter::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_invalid_after_t* +ScriptInvalidAfter::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_invalid_after_t* +ScriptInvalidAfter::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptInvalidAfter::ScriptInvalidAfter(cardano_script_invalid_after_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptInvalidBefore.cpp b/lib/src/Scripts/NativeScripts/ScriptInvalidBefore.cpp index a19b868a..9f6284cf 100644 --- a/lib/src/Scripts/NativeScripts/ScriptInvalidBefore.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptInvalidBefore.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -174,6 +176,35 @@ ScriptInvalidBefore::operator!=(const ScriptInvalidBefore& other) const return !(*this == other); } +ScriptInvalidBefore +ScriptInvalidBefore::adopt(cardano_script_invalid_before_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptInvalidBefore"); + } + + return ScriptInvalidBefore(*value); +} + +cardano_script_invalid_before_t* +ScriptInvalidBefore::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_invalid_before_t* +ScriptInvalidBefore::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_invalid_before_t* +ScriptInvalidBefore::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptInvalidBefore::ScriptInvalidBefore(cardano_script_invalid_before_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptNOfK.cpp b/lib/src/Scripts/NativeScripts/ScriptNOfK.cpp index 7a116bb6..a7da5425 100644 --- a/lib/src/Scripts/NativeScripts/ScriptNOfK.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptNOfK.cpp @@ -26,12 +26,15 @@ #include #include "../../CardanoInterop.h" +#include "../../ValueValidation.h" #include #include #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -42,7 +45,7 @@ ScriptNOfK::ScriptNOfK(std::size_t required, const NativeScriptList& scripts) NativeScriptList copy(scripts); cardano_script_n_of_k_t* value = nullptr; - const cardano_error_t result = cardano_script_n_of_k_new(copy.checked(), required, &value); + const cardano_error_t result = cardano_script_n_of_k_new(checkedNativeHandle(copy), required, &value); CardanoObject owner(value); @@ -79,7 +82,7 @@ ScriptNOfK::fromCbor(const std::vector& cbor) { ScriptNOfK value(*decodeCbor(cbor, cardano_script_n_of_k_from_cbor)); - value.scripts().validate(); + validateValue(value.scripts()); return value; } @@ -127,7 +130,7 @@ ScriptNOfK::scripts() const checkCardanoError(result, "ScriptNOfK scripts"); - const NativeScriptList list(*owner.release()); + const NativeScriptList list = NativeScriptList::adopt(owner.release()); return NativeScriptList(list); } @@ -137,7 +140,7 @@ ScriptNOfK::setScripts(const NativeScriptList& scripts) { NativeScriptList copy(scripts); - checkCardanoError(cardano_script_n_of_k_set_scripts(checked(), copy.checked()), "ScriptNOfK setScripts"); + checkCardanoError(cardano_script_n_of_k_set_scripts(checked(), checkedNativeHandle(copy)), "ScriptNOfK setScripts"); } std::size_t @@ -213,6 +216,35 @@ ScriptNOfK::operator!=(const ScriptNOfK& other) const return !(*this == other); } +ScriptNOfK +ScriptNOfK::adopt(cardano_script_n_of_k_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptNOfK"); + } + + return ScriptNOfK(*value); +} + +cardano_script_n_of_k_t* +ScriptNOfK::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_n_of_k_t* +ScriptNOfK::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_n_of_k_t* +ScriptNOfK::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptNOfK::ScriptNOfK(cardano_script_n_of_k_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptPubkey.cpp b/lib/src/Scripts/NativeScripts/ScriptPubkey.cpp index e8d0723c..ba0a5d6f 100644 --- a/lib/src/Scripts/NativeScripts/ScriptPubkey.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptPubkey.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -45,7 +47,7 @@ ScriptPubkey::ScriptPubkey(const Blake2bHash& keyHash) } cardano_script_pubkey_t* value = nullptr; - const cardano_error_t result = cardano_script_pubkey_new(copy.checked(), &value); + const cardano_error_t result = cardano_script_pubkey_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -119,7 +121,7 @@ ScriptPubkey::keyHash() const checkCardanoError(result, "ScriptPubkey keyHash"); - const Blake2bHash component(owner.release()); + const Blake2bHash component = Blake2bHash::adopt(owner.release()); return Blake2bHash(component); } @@ -134,7 +136,7 @@ ScriptPubkey::setKeyHash(const Blake2bHash& keyHash) throw std::invalid_argument("Script key hash must be 28 bytes"); } - checkCardanoError(cardano_script_pubkey_set_key_hash(checked(), copy.checked()), "ScriptPubkey setKeyHash"); + checkCardanoError(cardano_script_pubkey_set_key_hash(checked(), checkedNativeHandle(copy)), "ScriptPubkey setKeyHash"); } std::vector @@ -198,6 +200,35 @@ ScriptPubkey::operator!=(const ScriptPubkey& other) const return !(*this == other); } +ScriptPubkey +ScriptPubkey::adopt(cardano_script_pubkey_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptPubkey"); + } + + return ScriptPubkey(*value); +} + +cardano_script_pubkey_t* +ScriptPubkey::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_pubkey_t* +ScriptPubkey::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_pubkey_t* +ScriptPubkey::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptPubkey::ScriptPubkey(cardano_script_pubkey_t& value) noexcept diff --git a/lib/src/Scripts/NativeScripts/ScriptRequireGuard.cpp b/lib/src/Scripts/NativeScripts/ScriptRequireGuard.cpp index 01268af0..2af38c51 100644 --- a/lib/src/Scripts/NativeScripts/ScriptRequireGuard.cpp +++ b/lib/src/Scripts/NativeScripts/ScriptRequireGuard.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -40,7 +42,7 @@ ScriptRequireGuard::ScriptRequireGuard(const Credential& credential) Credential copy(credential); cardano_script_require_guard_t* value = nullptr; - const cardano_error_t result = cardano_script_require_guard_new(copy.checked(), &value); + const cardano_error_t result = cardano_script_require_guard_new(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -120,7 +122,7 @@ ScriptRequireGuard::credential() const checkCardanoError(result, "ScriptRequireGuard credential"); - const Credential component(owner.release()); + const Credential component = Credential::adopt(owner.release()); return Credential(component); } @@ -130,7 +132,7 @@ ScriptRequireGuard::setCredential(const Credential& credential) { Credential copy(credential); - checkCardanoError(cardano_script_require_guard_set_credential(checked(), copy.checked()), "ScriptRequireGuard setCredential"); + checkCardanoError(cardano_script_require_guard_set_credential(checked(), checkedNativeHandle(copy)), "ScriptRequireGuard setCredential"); } std::vector @@ -194,6 +196,35 @@ ScriptRequireGuard::operator!=(const ScriptRequireGuard& other) const return !(*this == other); } +ScriptRequireGuard +ScriptRequireGuard::adopt(cardano_script_require_guard_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null ScriptRequireGuard"); + } + + return ScriptRequireGuard(*value); +} + +cardano_script_require_guard_t* +ScriptRequireGuard::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_require_guard_t* +ScriptRequireGuard::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_require_guard_t* +ScriptRequireGuard::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ ScriptRequireGuard::ScriptRequireGuard(cardano_script_require_guard_t& value) noexcept diff --git a/lib/src/Scripts/PlutusScripts/PlutusV1Script.cpp b/lib/src/Scripts/PlutusScripts/PlutusV1Script.cpp index 8a29dffc..5ac46795 100644 --- a/lib/src/Scripts/PlutusScripts/PlutusV1Script.cpp +++ b/lib/src/Scripts/PlutusScripts/PlutusV1Script.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -148,7 +150,7 @@ PlutusV1Script::applyParameters(const PlutusList& parameters) const { const std::vector bytes = toBytes(); cardano_buffer_t* value = nullptr; - const cardano_error_t result = cardano_uplc_apply_params_to_script(parameters.checked(), byteData(bytes), bytes.size(), &value); + const cardano_error_t result = cardano_uplc_apply_params_to_script(checkedNativeHandle(parameters), byteData(bytes), bytes.size(), &value); CardanoObject owner(value); @@ -215,6 +217,35 @@ PlutusV1Script::operator!=(const PlutusV1Script& other) const return !(*this == other); } +PlutusV1Script +PlutusV1Script::adopt(cardano_plutus_v1_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV1Script"); + } + + return PlutusV1Script(*value); +} + +cardano_plutus_v1_script_t* +PlutusV1Script::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_plutus_v1_script_t* +PlutusV1Script::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_plutus_v1_script_t* +PlutusV1Script::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV1Script::PlutusV1Script(cardano_plutus_v1_script_t& value) noexcept diff --git a/lib/src/Scripts/PlutusScripts/PlutusV2Script.cpp b/lib/src/Scripts/PlutusScripts/PlutusV2Script.cpp index 28a36ad0..1383059f 100644 --- a/lib/src/Scripts/PlutusScripts/PlutusV2Script.cpp +++ b/lib/src/Scripts/PlutusScripts/PlutusV2Script.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -148,7 +150,7 @@ PlutusV2Script::applyParameters(const PlutusList& parameters) const { const std::vector bytes = toBytes(); cardano_buffer_t* value = nullptr; - const cardano_error_t result = cardano_uplc_apply_params_to_script(parameters.checked(), byteData(bytes), bytes.size(), &value); + const cardano_error_t result = cardano_uplc_apply_params_to_script(checkedNativeHandle(parameters), byteData(bytes), bytes.size(), &value); CardanoObject owner(value); @@ -215,6 +217,35 @@ PlutusV2Script::operator!=(const PlutusV2Script& other) const return !(*this == other); } +PlutusV2Script +PlutusV2Script::adopt(cardano_plutus_v2_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV2Script"); + } + + return PlutusV2Script(*value); +} + +cardano_plutus_v2_script_t* +PlutusV2Script::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_plutus_v2_script_t* +PlutusV2Script::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_plutus_v2_script_t* +PlutusV2Script::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV2Script::PlutusV2Script(cardano_plutus_v2_script_t& value) noexcept diff --git a/lib/src/Scripts/PlutusScripts/PlutusV3Script.cpp b/lib/src/Scripts/PlutusScripts/PlutusV3Script.cpp index c4801dba..3bc4a432 100644 --- a/lib/src/Scripts/PlutusScripts/PlutusV3Script.cpp +++ b/lib/src/Scripts/PlutusScripts/PlutusV3Script.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -148,7 +150,7 @@ PlutusV3Script::applyParameters(const PlutusList& parameters) const { const std::vector bytes = toBytes(); cardano_buffer_t* value = nullptr; - const cardano_error_t result = cardano_uplc_apply_params_to_script(parameters.checked(), byteData(bytes), bytes.size(), &value); + const cardano_error_t result = cardano_uplc_apply_params_to_script(checkedNativeHandle(parameters), byteData(bytes), bytes.size(), &value); CardanoObject owner(value); @@ -215,6 +217,35 @@ PlutusV3Script::operator!=(const PlutusV3Script& other) const return !(*this == other); } +PlutusV3Script +PlutusV3Script::adopt(cardano_plutus_v3_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV3Script"); + } + + return PlutusV3Script(*value); +} + +cardano_plutus_v3_script_t* +PlutusV3Script::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_plutus_v3_script_t* +PlutusV3Script::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_plutus_v3_script_t* +PlutusV3Script::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV3Script::PlutusV3Script(cardano_plutus_v3_script_t& value) noexcept diff --git a/lib/src/Scripts/PlutusScripts/PlutusV4Script.cpp b/lib/src/Scripts/PlutusScripts/PlutusV4Script.cpp index 20c37534..7bc2a492 100644 --- a/lib/src/Scripts/PlutusScripts/PlutusV4Script.cpp +++ b/lib/src/Scripts/PlutusScripts/PlutusV4Script.cpp @@ -30,6 +30,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -148,7 +150,7 @@ PlutusV4Script::applyParameters(const PlutusList& parameters) const { const std::vector bytes = toBytes(); cardano_buffer_t* value = nullptr; - const cardano_error_t result = cardano_uplc_apply_params_to_script(parameters.checked(), byteData(bytes), bytes.size(), &value); + const cardano_error_t result = cardano_uplc_apply_params_to_script(checkedNativeHandle(parameters), byteData(bytes), bytes.size(), &value); CardanoObject owner(value); @@ -215,6 +217,35 @@ PlutusV4Script::operator!=(const PlutusV4Script& other) const return !(*this == other); } +PlutusV4Script +PlutusV4Script::adopt(cardano_plutus_v4_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null PlutusV4Script"); + } + + return PlutusV4Script(*value); +} + +cardano_plutus_v4_script_t* +PlutusV4Script::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_plutus_v4_script_t* +PlutusV4Script::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_plutus_v4_script_t* +PlutusV4Script::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ PlutusV4Script::PlutusV4Script(cardano_plutus_v4_script_t& value) noexcept diff --git a/lib/src/Scripts/Script.cpp b/lib/src/Scripts/Script.cpp index f25ec370..82b88c39 100644 --- a/lib/src/Scripts/Script.cpp +++ b/lib/src/Scripts/Script.cpp @@ -26,6 +26,7 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include #include @@ -81,7 +82,7 @@ Script::Script(const NativeScript& script) NativeScript copy(script); cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_native(copy.checked(), &value); + const cardano_error_t result = cardano_script_new_native(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -94,7 +95,7 @@ Script::Script(NativeScript&& script) : m_value(nullptr) { cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_native(script.checked(), &value); + const cardano_error_t result = cardano_script_new_native(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -111,7 +112,7 @@ Script::Script(const PlutusV1Script& script) PlutusV1Script copy(script); cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v1(copy.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v1(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -124,7 +125,7 @@ Script::Script(PlutusV1Script&& script) : m_value(nullptr) { cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v1(script.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v1(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -141,7 +142,7 @@ Script::Script(const PlutusV2Script& script) PlutusV2Script copy(script); cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v2(copy.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v2(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -154,7 +155,7 @@ Script::Script(PlutusV2Script&& script) : m_value(nullptr) { cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v2(script.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v2(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -171,7 +172,7 @@ Script::Script(const PlutusV3Script& script) PlutusV3Script copy(script); cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v3(copy.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v3(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -184,7 +185,7 @@ Script::Script(PlutusV3Script&& script) : m_value(nullptr) { cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v3(script.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v3(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -201,7 +202,7 @@ Script::Script(const PlutusV4Script& script) PlutusV4Script copy(script); cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v4(copy.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v4(checkedNativeHandle(copy), &value); CardanoObject owner(value); @@ -214,7 +215,7 @@ Script::Script(PlutusV4Script&& script) : m_value(nullptr) { cardano_script_t* value = nullptr; - const cardano_error_t result = cardano_script_new_plutus_v4(script.checked(), &value); + const cardano_error_t result = cardano_script_new_plutus_v4(checkedNativeHandle(script), &value); CardanoObject owner(value); @@ -253,7 +254,7 @@ Script::fromCbor(const std::vector& cbor) { Script value(*decodeCbor(cbor, cardano_script_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -283,7 +284,7 @@ Script::asNative() const checkCardanoError(result, "Script asNative"); - const NativeScript component(*owner.release()); + const NativeScript component = NativeScript::adopt(owner.release()); return NativeScript(component); } @@ -298,7 +299,7 @@ Script::asPlutusV1() const checkCardanoError(result, "Script asPlutusV1"); - const PlutusV1Script component(*owner.release()); + const PlutusV1Script component = PlutusV1Script::adopt(owner.release()); return PlutusV1Script(component); } @@ -313,7 +314,7 @@ Script::asPlutusV2() const checkCardanoError(result, "Script asPlutusV2"); - const PlutusV2Script component(*owner.release()); + const PlutusV2Script component = PlutusV2Script::adopt(owner.release()); return PlutusV2Script(component); } @@ -328,7 +329,7 @@ Script::asPlutusV3() const checkCardanoError(result, "Script asPlutusV3"); - const PlutusV3Script component(*owner.release()); + const PlutusV3Script component = PlutusV3Script::adopt(owner.release()); return PlutusV3Script(component); } @@ -343,7 +344,7 @@ Script::asPlutusV4() const checkCardanoError(result, "Script asPlutusV4"); - const PlutusV4Script component(*owner.release()); + const PlutusV4Script component = PlutusV4Script::adopt(owner.release()); return PlutusV4Script(component); } @@ -423,6 +424,35 @@ Script::operator!=(const Script& other) const return !(*this == other); } +Script +Script::adopt(cardano_script_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Script"); + } + + return Script(*value); +} + +cardano_script_t* +Script::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_script_t* +Script::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_script_t* +Script::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Script::Script(cardano_script_t& value) noexcept @@ -442,11 +472,11 @@ Script::checked() const } void -Script::validate() const +validateValue(const Script& value) { - if (language() == ScriptLanguage::Native) + if (value.language() == ScriptLanguage::Native) { - asNative().validate(); + validateValue(value.asNative()); } } diff --git a/lib/src/Transaction/SubTransaction.cpp b/lib/src/Transaction/SubTransaction.cpp index 2b7e2b1f..a8141371 100644 --- a/lib/src/Transaction/SubTransaction.cpp +++ b/lib/src/Transaction/SubTransaction.cpp @@ -34,6 +34,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -45,7 +47,7 @@ SubTransaction::SubTransaction(const SubTransactionBody& body, const WitnessSet& const WitnessSet witnessCopy(witnesses); std::optional auxiliaryCopy(auxiliaryData); cardano_sub_transaction_t* value = nullptr; - const cardano_error_t status = cardano_sub_transaction_new(bodyCopy.checked(), witnessCopy.checked(), auxiliaryCopy ? auxiliaryCopy->checked() : nullptr, &value); + const cardano_error_t status = cardano_sub_transaction_new(checkedNativeHandle(bodyCopy), checkedNativeHandle(witnessCopy), auxiliaryCopy ? checkedNativeHandle(*auxiliaryCopy) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "SubTransaction"); @@ -95,7 +97,7 @@ SubTransaction::body() const } CardanoObject owner(value); - const SubTransactionBody copied(owner.release()); + const SubTransactionBody copied = SubTransactionBody::adopt(owner.release()); return SubTransactionBody(copied); } @@ -103,7 +105,7 @@ void SubTransaction::setBody(const SubTransactionBody& value) { const SubTransactionBody copy(value); - checkCardanoError(cardano_sub_transaction_set_body(checked(), copy.checked()), "SubTransaction setBody"); + checkCardanoError(cardano_sub_transaction_set_body(checked(), checkedNativeHandle(copy)), "SubTransaction setBody"); cardano_sub_transaction_clear_cbor_cache(checked()); } @@ -117,7 +119,7 @@ SubTransaction::witnessSet() const } CardanoObject owner(value); - const WitnessSet copied(owner.release()); + const WitnessSet copied = WitnessSet::adopt(owner.release()); return WitnessSet(copied); } @@ -125,7 +127,7 @@ void SubTransaction::setWitnessSet(const WitnessSet& value) { const WitnessSet copy(value); - checkCardanoError(cardano_sub_transaction_set_witness_set(checked(), copy.checked()), "SubTransaction setWitnessSet"); + checkCardanoError(cardano_sub_transaction_set_witness_set(checked(), checkedNativeHandle(copy)), "SubTransaction setWitnessSet"); cardano_sub_transaction_clear_cbor_cache(checked()); } @@ -139,7 +141,7 @@ SubTransaction::auxiliaryData() const } CardanoObject owner(value); - const AuxiliaryData copied(*owner.release()); + const AuxiliaryData copied = AuxiliaryData::adopt(owner.release()); return AuxiliaryData(copied); } @@ -149,7 +151,7 @@ SubTransaction::setAuxiliaryData(const std::optional& value) if (value) { const AuxiliaryData copy(*value); - checkCardanoError(cardano_sub_transaction_set_auxiliary_data(checked(), copy.checked()), "SubTransaction setAuxiliaryData"); + checkCardanoError(cardano_sub_transaction_set_auxiliary_data(checked(), checkedNativeHandle(copy)), "SubTransaction setAuxiliaryData"); } else { @@ -169,7 +171,7 @@ SubTransaction::id() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -177,7 +179,7 @@ void SubTransaction::applyVkeyWitnesses(const VkeyWitnessSet& witnesses) { const VkeyWitnessSet copy(witnesses); - checkCardanoError(cardano_sub_transaction_apply_vkey_witnesses(checked(), copy.checked()), "SubTransaction applyVkeyWitnesses"); + checkCardanoError(cardano_sub_transaction_apply_vkey_witnesses(checked(), checkedNativeHandle(copy)), "SubTransaction applyVkeyWitnesses"); cardano_sub_transaction_clear_cbor_cache(checked()); } @@ -233,6 +235,35 @@ SubTransaction::operator!=(const SubTransaction& other) const return !(*this == other); } +SubTransaction +SubTransaction::adopt(cardano_sub_transaction_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null SubTransaction"); + } + + return SubTransaction(value); +} + +cardano_sub_transaction_t* +SubTransaction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_sub_transaction_t* +SubTransaction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_sub_transaction_t* +SubTransaction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ SubTransaction::SubTransaction(cardano_sub_transaction_t* value) noexcept diff --git a/lib/src/Transaction/SubTransactionSet.cpp b/lib/src/Transaction/SubTransactionSet.cpp index 30eab30c..8ee8402d 100644 --- a/lib/src/Transaction/SubTransactionSet.cpp +++ b/lib/src/Transaction/SubTransactionSet.cpp @@ -31,6 +31,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -97,7 +99,7 @@ void SubTransactionSet::add(const SubTransaction& value) { const SubTransaction copy(value); - checkCardanoError(cardano_sub_transaction_set_add(checked(), copy.checked()), "SubTransactionSet add"); + checkCardanoError(cardano_sub_transaction_set_add(checked(), checkedNativeHandle(copy)), "SubTransactionSet add"); invalidateElements(); } @@ -114,7 +116,7 @@ SubTransactionSet::at(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "SubTransactionSet at"); - const SubTransaction copied(owner.release()); + const SubTransaction copied = SubTransaction::adopt(owner.release()); return SubTransaction(copied); } @@ -122,7 +124,7 @@ std::optional SubTransactionSet::findById(const Blake2bHash& id) const { cardano_sub_transaction_t* value = nullptr; - const cardano_error_t status = cardano_sub_transaction_set_find_by_id(checked(), id.checked(), &value); + const cardano_error_t status = cardano_sub_transaction_set_find_by_id(checked(), checkedNativeHandle(id), &value); CardanoObject owner(value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -131,7 +133,7 @@ SubTransactionSet::findById(const Blake2bHash& id) const } checkCardanoError(status, "SubTransactionSet findById"); - const SubTransaction copied(owner.release()); + const SubTransaction copied = SubTransaction::adopt(owner.release()); return SubTransaction(copied); } @@ -380,6 +382,41 @@ SubTransactionSet::erase(const value_type& value) return 1; } +SubTransactionSet +SubTransactionSet::adopt(cardano_sub_transaction_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null SubTransactionSet"); + } + + return SubTransactionSet(value); +} + +cardano_sub_transaction_set_t* +SubTransactionSet::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_sub_transaction_set_t* +SubTransactionSet::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_sub_transaction_set_t* +SubTransactionSet::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ SubTransactionSet::SubTransactionSet(cardano_sub_transaction_set_t* value) noexcept diff --git a/lib/src/Transaction/Transaction.cpp b/lib/src/Transaction/Transaction.cpp index 17779606..c73357fc 100644 --- a/lib/src/Transaction/Transaction.cpp +++ b/lib/src/Transaction/Transaction.cpp @@ -42,6 +42,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -53,7 +55,7 @@ Transaction::Transaction(const TransactionBody& body, const WitnessSet& witnesse const WitnessSet witnessCopy(witnesses); std::optional auxiliaryCopy(auxiliaryData); cardano_transaction_t* value = nullptr; - const cardano_error_t status = cardano_transaction_new(bodyCopy.checked(), witnessCopy.checked(), auxiliaryCopy ? auxiliaryCopy->checked() : nullptr, &value); + const cardano_error_t status = cardano_transaction_new(checkedNativeHandle(bodyCopy), checkedNativeHandle(witnessCopy), auxiliaryCopy ? checkedNativeHandle(*auxiliaryCopy) : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "Transaction"); @@ -103,7 +105,7 @@ Transaction::body() const } CardanoObject owner(value); - const TransactionBody copied(owner.release()); + const TransactionBody copied = TransactionBody::adopt(owner.release()); return TransactionBody(copied); } @@ -111,7 +113,7 @@ void Transaction::setBody(const TransactionBody& value) { const TransactionBody copy(value); - checkCardanoError(cardano_transaction_set_body(checked(), copy.checked()), "Transaction setBody"); + checkCardanoError(cardano_transaction_set_body(checked(), checkedNativeHandle(copy)), "Transaction setBody"); cardano_transaction_clear_cbor_cache(checked()); } @@ -125,7 +127,7 @@ Transaction::witnessSet() const } CardanoObject owner(value); - const WitnessSet copied(owner.release()); + const WitnessSet copied = WitnessSet::adopt(owner.release()); return WitnessSet(copied); } @@ -133,7 +135,7 @@ void Transaction::setWitnessSet(const WitnessSet& value) { const WitnessSet copy(value); - checkCardanoError(cardano_transaction_set_witness_set(checked(), copy.checked()), "Transaction setWitnessSet"); + checkCardanoError(cardano_transaction_set_witness_set(checked(), checkedNativeHandle(copy)), "Transaction setWitnessSet"); cardano_transaction_clear_cbor_cache(checked()); } @@ -147,7 +149,7 @@ Transaction::auxiliaryData() const } CardanoObject owner(value); - const AuxiliaryData copied(*owner.release()); + const AuxiliaryData copied = AuxiliaryData::adopt(owner.release()); return AuxiliaryData(copied); } @@ -157,7 +159,7 @@ Transaction::setAuxiliaryData(const std::optional& value) if (value) { const AuxiliaryData copy(*value); - checkCardanoError(cardano_transaction_set_auxiliary_data(checked(), copy.checked()), "Transaction setAuxiliaryData"); + checkCardanoError(cardano_transaction_set_auxiliary_data(checked(), checkedNativeHandle(copy)), "Transaction setAuxiliaryData"); } else { @@ -177,7 +179,7 @@ Transaction::id() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -185,7 +187,7 @@ void Transaction::applyVkeyWitnesses(const VkeyWitnessSet& witnesses) { const VkeyWitnessSet copy(witnesses); - checkCardanoError(cardano_transaction_apply_vkey_witnesses(checked(), copy.checked()), "Transaction applyVkeyWitnesses"); + checkCardanoError(cardano_transaction_apply_vkey_witnesses(checked(), checkedNativeHandle(copy)), "Transaction applyVkeyWitnesses"); cardano_transaction_clear_cbor_cache(checked()); } @@ -219,7 +221,7 @@ Transaction::uniqueSigners(const UtxoList& resolvedInputs) const for (const Utxo& input: resolvedInputs) { const Utxo copy(input); - checkCardanoError(cardano_utxo_list_add(list, copy.checked()), "Transaction uniqueSigners"); + checkCardanoError(cardano_utxo_list_add(list, checkedNativeHandle(copy)), "Transaction uniqueSigners"); } cardano_blake2b_hash_set_t* hashes = nullptr; @@ -227,7 +229,7 @@ Transaction::uniqueSigners(const UtxoList& resolvedInputs) const CardanoObject owner(hashes); checkCardanoError(status, "Transaction uniqueSigners"); - const Blake2bHashSet copied(owner.release()); + const Blake2bHashSet copied = Blake2bHashSet::adopt(owner.release()); return Blake2bHashSet(copied); } @@ -236,7 +238,7 @@ Transaction::findInputIndex(const TransactionInput& input) const { const Blake2bHash inputId = input.id(); std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_input_index(checked(), inputId.checked(), input.index(), &index); + const cardano_error_t status = cardano_transaction_find_input_index(checked(), checkedNativeHandle(inputId), input.index(), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -251,7 +253,7 @@ Transaction::findReferenceInputIndex(const TransactionInput& input) const { const Blake2bHash inputId = input.id(); std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_reference_input_index(checked(), inputId.checked(), input.index(), &index); + const cardano_error_t status = cardano_transaction_find_reference_input_index(checked(), checkedNativeHandle(inputId), input.index(), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -265,7 +267,7 @@ std::optional Transaction::findOutputIndex(const Address& address, std::uint64_t minLovelace) const { std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_output_index(checked(), address.checked(), minLovelace, &index); + const cardano_error_t status = cardano_transaction_find_output_index(checked(), checkedNativeHandle(address), minLovelace, &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -279,7 +281,7 @@ std::optional Transaction::findMintPolicyIndex(const Blake2bHash& policyId) const { std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_mint_policy_index(checked(), policyId.checked(), &index); + const cardano_error_t status = cardano_transaction_find_mint_policy_index(checked(), checkedNativeHandle(policyId), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -293,7 +295,7 @@ std::optional Transaction::findWithdrawalIndex(const RewardAddress& address) const { std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_withdrawal_index(checked(), address.checked(), &index); + const cardano_error_t status = cardano_transaction_find_withdrawal_index(checked(), checkedNativeHandle(address), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -307,7 +309,7 @@ std::optional Transaction::findCertificateIndex(const Certificate& certificate) const { std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_certificate_index(checked(), certificate.checked(), &index); + const cardano_error_t status = cardano_transaction_find_certificate_index(checked(), checkedNativeHandle(certificate), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -321,7 +323,7 @@ std::optional Transaction::findVoteIndex(const Voter& voter) const { std::uint64_t index = 0; - const cardano_error_t status = cardano_transaction_find_vote_index(checked(), voter.checked(), &index); + const cardano_error_t status = cardano_transaction_find_vote_index(checked(), checkedNativeHandle(voter), &index); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { return std::nullopt; @@ -397,6 +399,35 @@ Transaction::operator!=(const Transaction& other) const return !(*this == other); } +Transaction +Transaction::adopt(cardano_transaction_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null Transaction"); + } + + return Transaction(value); +} + +cardano_transaction_t* +Transaction::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_transaction_t* +Transaction::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_transaction_t* +Transaction::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ Transaction::Transaction(cardano_transaction_t* value) noexcept diff --git a/lib/src/TransactionBody/AccountBalanceInterval.cpp b/lib/src/TransactionBody/AccountBalanceInterval.cpp index c3dbff8b..c2d072ef 100644 --- a/lib/src/TransactionBody/AccountBalanceInterval.cpp +++ b/lib/src/TransactionBody/AccountBalanceInterval.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -167,6 +169,35 @@ AccountBalanceInterval::operator!=(const AccountBalanceInterval& other) const return !(*this == other); } +AccountBalanceInterval +AccountBalanceInterval::adopt(cardano_account_balance_interval_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AccountBalanceInterval"); + } + + return AccountBalanceInterval(value); +} + +cardano_account_balance_interval_t* +AccountBalanceInterval::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_account_balance_interval_t* +AccountBalanceInterval::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_account_balance_interval_t* +AccountBalanceInterval::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AccountBalanceInterval::AccountBalanceInterval(cardano_account_balance_interval_t* value) noexcept diff --git a/lib/src/TransactionBody/AccountBalanceIntervalsMap.cpp b/lib/src/TransactionBody/AccountBalanceIntervalsMap.cpp index 787860fc..ef96ab31 100644 --- a/lib/src/TransactionBody/AccountBalanceIntervalsMap.cpp +++ b/lib/src/TransactionBody/AccountBalanceIntervalsMap.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -102,7 +104,7 @@ std::optional AccountBalanceIntervalsMap::get(const RewardAddress& address) const { cardano_account_balance_interval_t* value = nullptr; - const cardano_error_t status = cardano_account_balance_intervals_map_get(checked(), address.checked(), &value); + const cardano_error_t status = cardano_account_balance_intervals_map_get(checked(), checkedNativeHandle(address), &value); CardanoObject owner(value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -111,7 +113,7 @@ AccountBalanceIntervalsMap::get(const RewardAddress& address) const } checkCardanoError(status, "AccountBalanceIntervalsMap get"); - const AccountBalanceInterval copied(owner.release()); + const AccountBalanceInterval copied = AccountBalanceInterval::adopt(owner.release()); return AccountBalanceInterval(copied); } @@ -120,7 +122,7 @@ AccountBalanceIntervalsMap::insert(const RewardAddress& address, const AccountBa { const RewardAddress copyAddress(address); const AccountBalanceInterval copyInterval(interval); - checkCardanoError(cardano_account_balance_intervals_map_insert(checked(), copyAddress.checked(), copyInterval.checked()), "AccountBalanceIntervalsMap insert"); + checkCardanoError(cardano_account_balance_intervals_map_insert(checked(), checkedNativeHandle(copyAddress), checkedNativeHandle(copyInterval)), "AccountBalanceIntervalsMap insert"); invalidateElements(); } @@ -146,8 +148,8 @@ AccountBalanceIntervalsMap::entryAt(std::size_t index) const CardanoObject valueOwner(value); checkCardanoError(status, "AccountBalanceIntervalsMap entryAt"); - RewardAddress address(*keyOwner.release()); - AccountBalanceInterval interval(valueOwner.release()); + RewardAddress address = RewardAddress::adopt(keyOwner.release()); + AccountBalanceInterval interval = AccountBalanceInterval::adopt(valueOwner.release()); return std::make_pair(std::move(address), std::move(interval)); } @@ -460,6 +462,60 @@ AccountBalanceIntervalsMap::clear() m_mutableAccess = true; } +AccountBalanceIntervalsMap +AccountBalanceIntervalsMap::adopt(cardano_account_balance_intervals_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null AccountBalanceIntervalsMap"); + } + + return AccountBalanceIntervalsMap(value); +} + +cardano_account_balance_intervals_map_t* +AccountBalanceIntervalsMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_account_balance_intervals_map_t* +AccountBalanceIntervalsMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_account_balance_intervals_map_t* +AccountBalanceIntervalsMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ AccountBalanceIntervalsMap::AccountBalanceIntervalsMap(cardano_account_balance_intervals_map_t* value) noexcept diff --git a/lib/src/TransactionBody/DirectDepositMap.cpp b/lib/src/TransactionBody/DirectDepositMap.cpp index 0c120919..a0158b49 100644 --- a/lib/src/TransactionBody/DirectDepositMap.cpp +++ b/lib/src/TransactionBody/DirectDepositMap.cpp @@ -29,6 +29,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -102,7 +104,7 @@ std::optional DirectDepositMap::get(const RewardAddress& address) const { std::uint64_t amount = 0; - const cardano_error_t status = cardano_direct_deposit_map_get(checked(), address.checked(), &amount); + const cardano_error_t status = cardano_direct_deposit_map_get(checked(), checkedNativeHandle(address), &amount); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) { @@ -117,7 +119,7 @@ void DirectDepositMap::insert(const RewardAddress& address, std::uint64_t amount) { const RewardAddress copy(address); - checkCardanoError(cardano_direct_deposit_map_insert(checked(), copy.checked(), amount), "DirectDepositMap insert"); + checkCardanoError(cardano_direct_deposit_map_insert(checked(), checkedNativeHandle(copy), amount), "DirectDepositMap insert"); invalidateElements(); } @@ -142,7 +144,7 @@ DirectDepositMap::entryAt(std::size_t index) const CardanoObject owner(key); checkCardanoError(status, "DirectDepositMap entryAt"); - RewardAddress address(*owner.release()); + RewardAddress address = RewardAddress::adopt(owner.release()); return std::make_pair(std::move(address), amount); } @@ -461,6 +463,60 @@ DirectDepositMap::clear() m_mutableAccess = true; } +DirectDepositMap +DirectDepositMap::adopt(cardano_direct_deposit_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null DirectDepositMap"); + } + + return DirectDepositMap(value); +} + +cardano_direct_deposit_map_t* +DirectDepositMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_direct_deposit_map_t* +DirectDepositMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_direct_deposit_map_t* +DirectDepositMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ DirectDepositMap::DirectDepositMap(cardano_direct_deposit_map_t* value) noexcept diff --git a/lib/src/TransactionBody/GuardSet.cpp b/lib/src/TransactionBody/GuardSet.cpp index 4a8f535a..2a80a93e 100644 --- a/lib/src/TransactionBody/GuardSet.cpp +++ b/lib/src/TransactionBody/GuardSet.cpp @@ -30,6 +30,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -90,7 +92,7 @@ void GuardSet::add(const Credential& value) { const Credential copy(value); - checkCardanoError(cardano_guard_set_add(checked(), copy.checked()), "GuardSet add"); + checkCardanoError(cardano_guard_set_add(checked(), checkedNativeHandle(copy)), "GuardSet add"); invalidateElements(); } @@ -107,7 +109,7 @@ GuardSet::at(std::size_t index) const CardanoObject owner(value); checkCardanoError(status, "GuardSet at"); - const Credential copied(owner.release()); + const Credential copied = Credential::adopt(owner.release()); return Credential(copied); } @@ -362,6 +364,41 @@ GuardSet::erase(const value_type& value) return 1; } +GuardSet +GuardSet::adopt(cardano_guard_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null GuardSet"); + } + + return GuardSet(value); +} + +cardano_guard_set_t* +GuardSet::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_guard_set_t* +GuardSet::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_guard_set_t* +GuardSet::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ GuardSet::GuardSet(cardano_guard_set_t* value) noexcept diff --git a/lib/src/TransactionBody/RequiredGuardsMap.cpp b/lib/src/TransactionBody/RequiredGuardsMap.cpp index aeeecf7c..1e340d86 100644 --- a/lib/src/TransactionBody/RequiredGuardsMap.cpp +++ b/lib/src/TransactionBody/RequiredGuardsMap.cpp @@ -31,6 +31,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -104,7 +106,7 @@ bool RequiredGuardsMap::contains(const Credential& credential) const { cardano_plutus_data_t* value = nullptr; - const cardano_error_t status = cardano_required_guards_map_get(checked(), credential.checked(), &value); + const cardano_error_t status = cardano_required_guards_map_get(checked(), checkedNativeHandle(credential), &value); CardanoObject owner(value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -120,7 +122,7 @@ std::optional> RequiredGuardsMap::get(const Credential& credential) const { cardano_plutus_data_t* value = nullptr; - const cardano_error_t status = cardano_required_guards_map_get(checked(), credential.checked(), &value); + const cardano_error_t status = cardano_required_guards_map_get(checked(), checkedNativeHandle(credential), &value); CardanoObject owner(value); if (status == CARDANO_ERROR_ELEMENT_NOT_FOUND) @@ -134,7 +136,7 @@ RequiredGuardsMap::get(const Credential& credential) const return std::make_optional(std::optional()); } - const PlutusData copied(*owner.release()); + const PlutusData copied = PlutusData::adopt(owner.release()); return std::make_optional(std::make_optional(PlutusData(copied))); } @@ -146,11 +148,11 @@ RequiredGuardsMap::insert(const Credential& credential, const std::optional valueOwner(value); checkCardanoError(status, "RequiredGuardsMap entryAt"); - Credential credential(keyOwner.release()); + Credential credential = Credential::adopt(keyOwner.release()); std::optional datum; if (valueOwner.get()) { - PlutusData copied(*valueOwner.release()); - datum = std::move(copied); + PlutusData copied = PlutusData::adopt(valueOwner.release()); + datum = std::move(copied); } return std::make_pair(std::move(credential), std::move(datum)); @@ -491,6 +493,60 @@ RequiredGuardsMap::clear() m_mutableAccess = true; } +RequiredGuardsMap +RequiredGuardsMap::adopt(cardano_required_guards_map_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null RequiredGuardsMap"); + } + + return RequiredGuardsMap(value); +} + +cardano_required_guards_map_t* +RequiredGuardsMap::nativeHandle() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return m_value; +} + +const cardano_required_guards_map_t* +RequiredGuardsMap::nativeHandle() const +{ + if (m_value) + { + synchronize(); + } + + return m_value; +} + +cardano_required_guards_map_t* +RequiredGuardsMap::release() +{ + if (m_value) + { + synchronize(); + } + + m_elements.clear(); + m_encoding.clear(); + m_materialized = false; + m_mutableAccess = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ RequiredGuardsMap::RequiredGuardsMap(cardano_required_guards_map_t* value) noexcept diff --git a/lib/src/TransactionBody/SubTransactionBody.cpp b/lib/src/TransactionBody/SubTransactionBody.cpp index c3f3fa52..0ebdbf94 100644 --- a/lib/src/TransactionBody/SubTransactionBody.cpp +++ b/lib/src/TransactionBody/SubTransactionBody.cpp @@ -42,6 +42,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -52,7 +54,7 @@ SubTransactionBody::SubTransactionBody(const TransactionInputSet& inputs, const const TransactionInputSet inputCopy(inputs); const TransactionOutputList outputCopy(outputs); cardano_sub_transaction_body_t* value = nullptr; - const cardano_error_t status = cardano_sub_transaction_body_new(inputCopy.checked(), outputCopy.checked(), invalidAfter ? &*invalidAfter : nullptr, &value); + const cardano_error_t status = cardano_sub_transaction_body_new(checkedNativeHandle(inputCopy), checkedNativeHandle(outputCopy), invalidAfter ? &*invalidAfter : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "SubTransactionBody"); @@ -102,7 +104,7 @@ SubTransactionBody::inputs() const } CardanoObject owner(value); - const TransactionInputSet copied(*owner.release()); + const TransactionInputSet copied = TransactionInputSet::adopt(owner.release()); return TransactionInputSet(copied); } @@ -110,7 +112,7 @@ void SubTransactionBody::setInputs(const TransactionInputSet& value) { const TransactionInputSet copy(value); - checkCardanoError(cardano_sub_transaction_body_set_inputs(checked(), copy.checked()), "SubTransactionBody setInputs"); + checkCardanoError(cardano_sub_transaction_body_set_inputs(checked(), checkedNativeHandle(copy)), "SubTransactionBody setInputs"); cardano_sub_transaction_body_clear_cbor_cache(checked()); } @@ -125,7 +127,7 @@ SubTransactionBody::outputs() const } CardanoObject owner(value); - const TransactionOutputList copied(*owner.release()); + const TransactionOutputList copied = TransactionOutputList::adopt(owner.release()); return TransactionOutputList(copied); } @@ -133,7 +135,7 @@ void SubTransactionBody::setOutputs(const TransactionOutputList& value) { const TransactionOutputList copy(value); - checkCardanoError(cardano_sub_transaction_body_set_outputs(checked(), copy.checked()), "SubTransactionBody setOutputs"); + checkCardanoError(cardano_sub_transaction_body_set_outputs(checked(), checkedNativeHandle(copy)), "SubTransactionBody setOutputs"); cardano_sub_transaction_body_clear_cbor_cache(checked()); } @@ -148,7 +150,7 @@ SubTransactionBody::certificates() const } CardanoObject owner(value); - const CertificateSet copied(owner.release()); + const CertificateSet copied = CertificateSet::adopt(owner.release()); return CertificateSet(copied); } @@ -158,7 +160,7 @@ SubTransactionBody::setCertificates(const std::optional& value) if (value) { const CertificateSet copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_certificates(checked(), copy.checked()), "SubTransactionBody setCertificates"); + checkCardanoError(cardano_sub_transaction_body_set_certificates(checked(), checkedNativeHandle(copy)), "SubTransactionBody setCertificates"); } else { @@ -178,7 +180,7 @@ SubTransactionBody::withdrawals() const } CardanoObject owner(value); - const WithdrawalMap copied(*owner.release()); + const WithdrawalMap copied = WithdrawalMap::adopt(owner.release()); return WithdrawalMap(copied); } @@ -188,7 +190,7 @@ SubTransactionBody::setWithdrawals(const std::optional& value) if (value) { const WithdrawalMap copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_withdrawals(checked(), copy.checked()), "SubTransactionBody setWithdrawals"); + checkCardanoError(cardano_sub_transaction_body_set_withdrawals(checked(), checkedNativeHandle(copy)), "SubTransactionBody setWithdrawals"); } else { @@ -208,7 +210,7 @@ SubTransactionBody::auxDataHash() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -218,7 +220,7 @@ SubTransactionBody::setAuxDataHash(const std::optional& value) if (value) { const Blake2bHash copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_aux_data_hash(checked(), copy.checked()), "SubTransactionBody setAuxDataHash"); + checkCardanoError(cardano_sub_transaction_body_set_aux_data_hash(checked(), checkedNativeHandle(copy)), "SubTransactionBody setAuxDataHash"); } else { @@ -238,7 +240,7 @@ SubTransactionBody::mint() const } CardanoObject owner(value); - const MultiAsset copied(owner.release()); + const MultiAsset copied = MultiAsset::adopt(owner.release()); return MultiAsset(copied); } @@ -248,7 +250,7 @@ SubTransactionBody::setMint(const std::optional& value) if (value) { const MultiAsset copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_mint(checked(), copy.checked()), "SubTransactionBody setMint"); + checkCardanoError(cardano_sub_transaction_body_set_mint(checked(), checkedNativeHandle(copy)), "SubTransactionBody setMint"); } else { @@ -268,7 +270,7 @@ SubTransactionBody::scriptDataHash() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -278,7 +280,7 @@ SubTransactionBody::setScriptDataHash(const std::optional& value) if (value) { const Blake2bHash copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_script_data_hash(checked(), copy.checked()), "SubTransactionBody setScriptDataHash"); + checkCardanoError(cardano_sub_transaction_body_set_script_data_hash(checked(), checkedNativeHandle(copy)), "SubTransactionBody setScriptDataHash"); } else { @@ -298,7 +300,7 @@ SubTransactionBody::guards() const } CardanoObject owner(value); - const GuardSet copied(owner.release()); + const GuardSet copied = GuardSet::adopt(owner.release()); return GuardSet(copied); } @@ -308,7 +310,7 @@ SubTransactionBody::setGuards(const std::optional& value) if (value) { const GuardSet copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_guards(checked(), copy.checked()), "SubTransactionBody setGuards"); + checkCardanoError(cardano_sub_transaction_body_set_guards(checked(), checkedNativeHandle(copy)), "SubTransactionBody setGuards"); } else { @@ -328,7 +330,7 @@ SubTransactionBody::referenceInputs() const } CardanoObject owner(value); - const TransactionInputSet copied(*owner.release()); + const TransactionInputSet copied = TransactionInputSet::adopt(owner.release()); return TransactionInputSet(copied); } @@ -338,7 +340,7 @@ SubTransactionBody::setReferenceInputs(const std::optional& if (value) { const TransactionInputSet copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_reference_inputs(checked(), copy.checked()), "SubTransactionBody setReferenceInputs"); + checkCardanoError(cardano_sub_transaction_body_set_reference_inputs(checked(), checkedNativeHandle(copy)), "SubTransactionBody setReferenceInputs"); } else { @@ -358,7 +360,7 @@ SubTransactionBody::votingProcedures() const } CardanoObject owner(value); - const VotingProcedures copied(owner.release()); + const VotingProcedures copied = VotingProcedures::adopt(owner.release()); return VotingProcedures(copied); } @@ -368,7 +370,7 @@ SubTransactionBody::setVotingProcedures(const std::optional& v if (value) { const VotingProcedures copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_voting_procedures(checked(), copy.checked()), "SubTransactionBody setVotingProcedures"); + checkCardanoError(cardano_sub_transaction_body_set_voting_procedures(checked(), checkedNativeHandle(copy)), "SubTransactionBody setVotingProcedures"); } else { @@ -388,7 +390,7 @@ SubTransactionBody::proposalProcedures() const } CardanoObject owner(value); - const ProposalProcedureSet copied(owner.release()); + const ProposalProcedureSet copied = ProposalProcedureSet::adopt(owner.release()); return ProposalProcedureSet(copied); } @@ -398,7 +400,7 @@ SubTransactionBody::setProposalProcedures(const std::optional owner(value); - const RequiredGuardsMap copied(owner.release()); + const RequiredGuardsMap copied = RequiredGuardsMap::adopt(owner.release()); return RequiredGuardsMap(copied); } @@ -428,7 +430,7 @@ SubTransactionBody::setRequiredTopLevelGuards(const std::optional owner(value); - const DirectDepositMap copied(owner.release()); + const DirectDepositMap copied = DirectDepositMap::adopt(owner.release()); return DirectDepositMap(copied); } @@ -458,7 +460,7 @@ SubTransactionBody::setDirectDeposits(const std::optional& val if (value) { const DirectDepositMap copy(*value); - checkCardanoError(cardano_sub_transaction_body_set_direct_deposits(checked(), copy.checked()), "SubTransactionBody setDirectDeposits"); + checkCardanoError(cardano_sub_transaction_body_set_direct_deposits(checked(), checkedNativeHandle(copy)), "SubTransactionBody setDirectDeposits"); } else { @@ -478,7 +480,7 @@ SubTransactionBody::accountBalanceIntervals() const } CardanoObject owner(value); - const AccountBalanceIntervalsMap copied(owner.release()); + const AccountBalanceIntervalsMap copied = AccountBalanceIntervalsMap::adopt(owner.release()); return AccountBalanceIntervalsMap(copied); } @@ -488,7 +490,7 @@ SubTransactionBody::setAccountBalanceIntervals(const std::optional owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -660,6 +662,35 @@ SubTransactionBody::operator!=(const SubTransactionBody& other) const return !(*this == other); } +SubTransactionBody +SubTransactionBody::adopt(cardano_sub_transaction_body_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null SubTransactionBody"); + } + + return SubTransactionBody(value); +} + +cardano_sub_transaction_body_t* +SubTransactionBody::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_sub_transaction_body_t* +SubTransactionBody::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_sub_transaction_body_t* +SubTransactionBody::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ SubTransactionBody::SubTransactionBody(cardano_sub_transaction_body_t* value) noexcept diff --git a/lib/src/TransactionBody/TransactionBody.cpp b/lib/src/TransactionBody/TransactionBody.cpp index c13f5eb6..7aa52616 100644 --- a/lib/src/TransactionBody/TransactionBody.cpp +++ b/lib/src/TransactionBody/TransactionBody.cpp @@ -46,6 +46,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -56,7 +58,7 @@ TransactionBody::TransactionBody(const TransactionInputSet& inputs, const Transa const TransactionInputSet inputCopy(inputs); const TransactionOutputList outputCopy(outputs); cardano_transaction_body_t* value = nullptr; - const cardano_error_t status = cardano_transaction_body_new(inputCopy.checked(), outputCopy.checked(), fee, invalidAfter ? &*invalidAfter : nullptr, &value); + const cardano_error_t status = cardano_transaction_body_new(checkedNativeHandle(inputCopy), checkedNativeHandle(outputCopy), fee, invalidAfter ? &*invalidAfter : nullptr, &value); CardanoObject owner(value); checkCardanoError(status, "TransactionBody"); @@ -106,7 +108,7 @@ TransactionBody::inputs() const } CardanoObject owner(value); - const TransactionInputSet copied(*owner.release()); + const TransactionInputSet copied = TransactionInputSet::adopt(owner.release()); return TransactionInputSet(copied); } @@ -114,7 +116,7 @@ void TransactionBody::setInputs(const TransactionInputSet& value) { const TransactionInputSet copy(value); - checkCardanoError(cardano_transaction_body_set_inputs(checked(), copy.checked()), "TransactionBody setInputs"); + checkCardanoError(cardano_transaction_body_set_inputs(checked(), checkedNativeHandle(copy)), "TransactionBody setInputs"); cardano_transaction_body_clear_cbor_cache(checked()); } @@ -129,7 +131,7 @@ TransactionBody::outputs() const } CardanoObject owner(value); - const TransactionOutputList copied(*owner.release()); + const TransactionOutputList copied = TransactionOutputList::adopt(owner.release()); return TransactionOutputList(copied); } @@ -137,7 +139,7 @@ void TransactionBody::setOutputs(const TransactionOutputList& value) { const TransactionOutputList copy(value); - checkCardanoError(cardano_transaction_body_set_outputs(checked(), copy.checked()), "TransactionBody setOutputs"); + checkCardanoError(cardano_transaction_body_set_outputs(checked(), checkedNativeHandle(copy)), "TransactionBody setOutputs"); cardano_transaction_body_clear_cbor_cache(checked()); } @@ -152,7 +154,7 @@ TransactionBody::certificates() const } CardanoObject owner(value); - const CertificateSet copied(owner.release()); + const CertificateSet copied = CertificateSet::adopt(owner.release()); return CertificateSet(copied); } @@ -162,7 +164,7 @@ TransactionBody::setCertificates(const std::optional& value) if (value) { const CertificateSet copy(*value); - checkCardanoError(cardano_transaction_body_set_certificates(checked(), copy.checked()), "TransactionBody setCertificates"); + checkCardanoError(cardano_transaction_body_set_certificates(checked(), checkedNativeHandle(copy)), "TransactionBody setCertificates"); } else { @@ -182,7 +184,7 @@ TransactionBody::withdrawals() const } CardanoObject owner(value); - const WithdrawalMap copied(*owner.release()); + const WithdrawalMap copied = WithdrawalMap::adopt(owner.release()); return WithdrawalMap(copied); } @@ -192,7 +194,7 @@ TransactionBody::setWithdrawals(const std::optional& value) if (value) { const WithdrawalMap copy(*value); - checkCardanoError(cardano_transaction_body_set_withdrawals(checked(), copy.checked()), "TransactionBody setWithdrawals"); + checkCardanoError(cardano_transaction_body_set_withdrawals(checked(), checkedNativeHandle(copy)), "TransactionBody setWithdrawals"); } else { @@ -212,7 +214,7 @@ TransactionBody::auxDataHash() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -222,7 +224,7 @@ TransactionBody::setAuxDataHash(const std::optional& value) if (value) { const Blake2bHash copy(*value); - checkCardanoError(cardano_transaction_body_set_aux_data_hash(checked(), copy.checked()), "TransactionBody setAuxDataHash"); + checkCardanoError(cardano_transaction_body_set_aux_data_hash(checked(), checkedNativeHandle(copy)), "TransactionBody setAuxDataHash"); } else { @@ -242,7 +244,7 @@ TransactionBody::mint() const } CardanoObject owner(value); - const MultiAsset copied(owner.release()); + const MultiAsset copied = MultiAsset::adopt(owner.release()); return MultiAsset(copied); } @@ -252,7 +254,7 @@ TransactionBody::setMint(const std::optional& value) if (value) { const MultiAsset copy(*value); - checkCardanoError(cardano_transaction_body_set_mint(checked(), copy.checked()), "TransactionBody setMint"); + checkCardanoError(cardano_transaction_body_set_mint(checked(), checkedNativeHandle(copy)), "TransactionBody setMint"); } else { @@ -272,7 +274,7 @@ TransactionBody::scriptDataHash() const } CardanoObject owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -282,7 +284,7 @@ TransactionBody::setScriptDataHash(const std::optional& value) if (value) { const Blake2bHash copy(*value); - checkCardanoError(cardano_transaction_body_set_script_data_hash(checked(), copy.checked()), "TransactionBody setScriptDataHash"); + checkCardanoError(cardano_transaction_body_set_script_data_hash(checked(), checkedNativeHandle(copy)), "TransactionBody setScriptDataHash"); } else { @@ -302,7 +304,7 @@ TransactionBody::guards() const } CardanoObject owner(value); - const GuardSet copied(owner.release()); + const GuardSet copied = GuardSet::adopt(owner.release()); return GuardSet(copied); } @@ -312,7 +314,7 @@ TransactionBody::setGuards(const std::optional& value) if (value) { const GuardSet copy(*value); - checkCardanoError(cardano_transaction_body_set_guards(checked(), copy.checked()), "TransactionBody setGuards"); + checkCardanoError(cardano_transaction_body_set_guards(checked(), checkedNativeHandle(copy)), "TransactionBody setGuards"); } else { @@ -332,7 +334,7 @@ TransactionBody::referenceInputs() const } CardanoObject owner(value); - const TransactionInputSet copied(*owner.release()); + const TransactionInputSet copied = TransactionInputSet::adopt(owner.release()); return TransactionInputSet(copied); } @@ -342,7 +344,7 @@ TransactionBody::setReferenceInputs(const std::optional& va if (value) { const TransactionInputSet copy(*value); - checkCardanoError(cardano_transaction_body_set_reference_inputs(checked(), copy.checked()), "TransactionBody setReferenceInputs"); + checkCardanoError(cardano_transaction_body_set_reference_inputs(checked(), checkedNativeHandle(copy)), "TransactionBody setReferenceInputs"); } else { @@ -362,7 +364,7 @@ TransactionBody::votingProcedures() const } CardanoObject owner(value); - const VotingProcedures copied(owner.release()); + const VotingProcedures copied = VotingProcedures::adopt(owner.release()); return VotingProcedures(copied); } @@ -372,7 +374,7 @@ TransactionBody::setVotingProcedures(const std::optional& valu if (value) { const VotingProcedures copy(*value); - checkCardanoError(cardano_transaction_body_set_voting_procedures(checked(), copy.checked()), "TransactionBody setVotingProcedures"); + checkCardanoError(cardano_transaction_body_set_voting_procedures(checked(), checkedNativeHandle(copy)), "TransactionBody setVotingProcedures"); } else { @@ -392,7 +394,7 @@ TransactionBody::proposalProcedures() const } CardanoObject owner(value); - const ProposalProcedureSet copied(owner.release()); + const ProposalProcedureSet copied = ProposalProcedureSet::adopt(owner.release()); return ProposalProcedureSet(copied); } @@ -402,7 +404,7 @@ TransactionBody::setProposalProcedures(const std::optional if (value) { const ProposalProcedureSet copy(*value); - checkCardanoError(cardano_transaction_body_set_proposal_procedure(checked(), copy.checked()), "TransactionBody setProposalProcedures"); + checkCardanoError(cardano_transaction_body_set_proposal_procedure(checked(), checkedNativeHandle(copy)), "TransactionBody setProposalProcedures"); } else { @@ -422,7 +424,7 @@ TransactionBody::requiredTopLevelGuards() const } CardanoObject owner(value); - const RequiredGuardsMap copied(owner.release()); + const RequiredGuardsMap copied = RequiredGuardsMap::adopt(owner.release()); return RequiredGuardsMap(copied); } @@ -432,7 +434,7 @@ TransactionBody::setRequiredTopLevelGuards(const std::optional owner(value); - const DirectDepositMap copied(owner.release()); + const DirectDepositMap copied = DirectDepositMap::adopt(owner.release()); return DirectDepositMap(copied); } @@ -462,7 +464,7 @@ TransactionBody::setDirectDeposits(const std::optional& value) if (value) { const DirectDepositMap copy(*value); - checkCardanoError(cardano_transaction_body_set_direct_deposits(checked(), copy.checked()), "TransactionBody setDirectDeposits"); + checkCardanoError(cardano_transaction_body_set_direct_deposits(checked(), checkedNativeHandle(copy)), "TransactionBody setDirectDeposits"); } else { @@ -482,7 +484,7 @@ TransactionBody::accountBalanceIntervals() const } CardanoObject owner(value); - const AccountBalanceIntervalsMap copied(owner.release()); + const AccountBalanceIntervalsMap copied = AccountBalanceIntervalsMap::adopt(owner.release()); return AccountBalanceIntervalsMap(copied); } @@ -492,7 +494,7 @@ TransactionBody::setAccountBalanceIntervals(const std::optional owner(value); - const Update copied(owner.release()); + const Update copied = Update::adopt(owner.release()); return Update(copied); } @@ -618,7 +620,7 @@ TransactionBody::setUpdate(const std::optional& value) if (value) { const Update copy(*value); - checkCardanoError(cardano_transaction_body_set_update(checked(), copy.checked()), "TransactionBody setUpdate"); + checkCardanoError(cardano_transaction_body_set_update(checked(), checkedNativeHandle(copy)), "TransactionBody setUpdate"); } else { @@ -638,7 +640,7 @@ TransactionBody::collateral() const } CardanoObject owner(value); - const TransactionInputSet copied(*owner.release()); + const TransactionInputSet copied = TransactionInputSet::adopt(owner.release()); return TransactionInputSet(copied); } @@ -648,7 +650,7 @@ TransactionBody::setCollateral(const std::optional& value) if (value) { const TransactionInputSet copy(*value); - checkCardanoError(cardano_transaction_body_set_collateral(checked(), copy.checked()), "TransactionBody setCollateral"); + checkCardanoError(cardano_transaction_body_set_collateral(checked(), checkedNativeHandle(copy)), "TransactionBody setCollateral"); } else { @@ -668,7 +670,7 @@ TransactionBody::requiredSigners() const } CardanoObject owner(value); - const Blake2bHashSet copied(owner.release()); + const Blake2bHashSet copied = Blake2bHashSet::adopt(owner.release()); return Blake2bHashSet(copied); } @@ -678,7 +680,7 @@ TransactionBody::setRequiredSigners(const std::optional& value) if (value) { const Blake2bHashSet copy(*value); - checkCardanoError(cardano_transaction_body_set_required_signers(checked(), copy.checked()), "TransactionBody setRequiredSigners"); + checkCardanoError(cardano_transaction_body_set_required_signers(checked(), checkedNativeHandle(copy)), "TransactionBody setRequiredSigners"); } else { @@ -698,7 +700,7 @@ TransactionBody::collateralReturn() const } CardanoObject owner(value); - const TransactionOutput copied(*owner.release()); + const TransactionOutput copied = TransactionOutput::adopt(owner.release()); return TransactionOutput(copied); } @@ -708,7 +710,7 @@ TransactionBody::setCollateralReturn(const std::optional& val if (value) { const TransactionOutput copy(*value); - checkCardanoError(cardano_transaction_body_set_collateral_return(checked(), copy.checked()), "TransactionBody setCollateralReturn"); + checkCardanoError(cardano_transaction_body_set_collateral_return(checked(), checkedNativeHandle(copy)), "TransactionBody setCollateralReturn"); } else { @@ -728,7 +730,7 @@ TransactionBody::subTransactions() const } CardanoObject owner(value); - const SubTransactionSet copied(owner.release()); + const SubTransactionSet copied = SubTransactionSet::adopt(owner.release()); return SubTransactionSet(copied); } @@ -738,7 +740,7 @@ TransactionBody::setSubTransactions(const std::optional& valu if (value) { const SubTransactionSet copy(*value); - checkCardanoError(cardano_transaction_body_set_sub_transactions(checked(), copy.checked()), "TransactionBody setSubTransactions"); + checkCardanoError(cardano_transaction_body_set_sub_transactions(checked(), checkedNativeHandle(copy)), "TransactionBody setSubTransactions"); } else { @@ -758,7 +760,7 @@ TransactionBody::startingAccountBalanceIntervals() const } CardanoObject owner(value); - const AccountBalanceIntervalsMap copied(owner.release()); + const AccountBalanceIntervalsMap copied = AccountBalanceIntervalsMap::adopt(owner.release()); return AccountBalanceIntervalsMap(copied); } @@ -768,7 +770,7 @@ TransactionBody::setStartingAccountBalanceIntervals(const std::optional owner(value); - const Blake2bHash copied(owner.release()); + const Blake2bHash copied = Blake2bHash::adopt(owner.release()); return Blake2bHash(copied); } @@ -877,6 +879,35 @@ TransactionBody::operator!=(const TransactionBody& other) const return !(*this == other); } +TransactionBody +TransactionBody::adopt(cardano_transaction_body_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null TransactionBody"); + } + + return TransactionBody(value); +} + +cardano_transaction_body_t* +TransactionBody::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_transaction_body_t* +TransactionBody::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_transaction_body_t* +TransactionBody::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ TransactionBody::TransactionBody(cardano_transaction_body_t* value) noexcept diff --git a/lib/src/TransactionBody/TransactionInput.cpp b/lib/src/TransactionBody/TransactionInput.cpp index c856290a..c75367a0 100644 --- a/lib/src/TransactionBody/TransactionInput.cpp +++ b/lib/src/TransactionBody/TransactionInput.cpp @@ -26,11 +26,14 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -41,7 +44,7 @@ TransactionInput::TransactionInput(const Blake2bHash& id, std::uint64_t index) Blake2bHash copy(id); cardano_transaction_input_t* value = nullptr; - const cardano_error_t result = cardano_transaction_input_new(copy.checked(), index, &value); + const cardano_error_t result = cardano_transaction_input_new(checkedNativeHandle(copy), index, &value); CardanoObject owner(value); @@ -78,7 +81,7 @@ TransactionInput::fromCbor(const std::vector& cbor) { TransactionInput value(*decodeCbor(cbor, cardano_transaction_input_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -101,7 +104,7 @@ TransactionInput::id() const cardano_blake2b_hash_t* value = cardano_transaction_input_get_id(checked()); CardanoObject owner(value); - const Blake2bHash component(owner.release()); + const Blake2bHash component = Blake2bHash::adopt(owner.release()); return Blake2bHash(component); } @@ -116,7 +119,7 @@ TransactionInput::setId(const Blake2bHash& value) throw std::invalid_argument("Transaction ID must be 32 bytes"); } - checkCardanoError(cardano_transaction_input_set_id(checked(), copy.checked()), "TransactionInput setId"); + checkCardanoError(cardano_transaction_input_set_id(checked(), checkedNativeHandle(copy)), "TransactionInput setId"); } std::uint64_t @@ -210,6 +213,35 @@ TransactionInput::operator!=(const TransactionInput& other) const return !(*this == other); } +TransactionInput +TransactionInput::adopt(cardano_transaction_input_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null TransactionInput"); + } + + return TransactionInput(*value); +} + +cardano_transaction_input_t* +TransactionInput::nativeHandle() noexcept +{ + return m_value; +} + +const cardano_transaction_input_t* +TransactionInput::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_transaction_input_t* +TransactionInput::release() noexcept +{ + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ TransactionInput::TransactionInput(cardano_transaction_input_t& value) noexcept @@ -229,9 +261,9 @@ TransactionInput::checked() const } void -TransactionInput::validate() const +validateValue(const TransactionInput& value) { - if (id().toBytes().size() != 32U) + if (value.id().toBytes().size() != 32U) { throw std::invalid_argument("Transaction ID must be 32 bytes"); } diff --git a/lib/src/TransactionBody/TransactionInputSet.cpp b/lib/src/TransactionBody/TransactionInputSet.cpp index 8364ef85..c128f23b 100644 --- a/lib/src/TransactionBody/TransactionInputSet.cpp +++ b/lib/src/TransactionBody/TransactionInputSet.cpp @@ -31,6 +31,8 @@ #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -139,7 +141,7 @@ TransactionInputSet::contains(const TransactionInput& value) const checkCardanoError(status, "TransactionInputSet contains"); - if (cardano_transaction_input_equals(owner.get(), value.checked())) + if (cardano_transaction_input_equals(owner.get(), checkedNativeHandle(value))) { return true; } @@ -161,7 +163,7 @@ TransactionInputSet::at(std::size_t index) const CardanoObject owner(element); checkCardanoError(status, "TransactionInputSet at"); - const TransactionInput value(*owner.release()); + const TransactionInput value = TransactionInput::adopt(owner.release()); return TransactionInput(value); } @@ -435,6 +437,41 @@ TransactionInputSet::erase(const value_type& value) return 1; } +TransactionInputSet +TransactionInputSet::adopt(cardano_transaction_input_set_t* value) +{ + if (!value) + { + throw std::invalid_argument("Cannot adopt a null TransactionInputSet"); + } + + return TransactionInputSet(*value); +} + +cardano_transaction_input_set_t* +TransactionInputSet::nativeHandle() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return m_value; +} + +const cardano_transaction_input_set_t* +TransactionInputSet::nativeHandle() const noexcept +{ + return m_value; +} + +cardano_transaction_input_set_t* +TransactionInputSet::release() noexcept +{ + m_elements.clear(); + m_materialized = false; + + return std::exchange(m_value, nullptr); +} + /* PRIVATE FUNCTIONS *********************************************************/ TransactionInputSet::TransactionInputSet(cardano_transaction_input_set_t& value) noexcept @@ -497,7 +534,7 @@ TransactionInputSet::insertValue(const TransactionInput& value) const TransactionInput copy(value); - checkCardanoError(cardano_transaction_input_set_add(checked(), copy.checked()), "TransactionInputSet insert"); + checkCardanoError(cardano_transaction_input_set_add(checked(), checkedNativeHandle(copy)), "TransactionInputSet insert"); invalidateElements(); return true; diff --git a/lib/src/TransactionBody/TransactionOutput.cpp b/lib/src/TransactionBody/TransactionOutput.cpp index e5485089..6cdd3793 100644 --- a/lib/src/TransactionBody/TransactionOutput.cpp +++ b/lib/src/TransactionBody/TransactionOutput.cpp @@ -26,6 +26,7 @@ #include #include "../CardanoInterop.h" +#include "../ValueValidation.h" #include @@ -34,6 +35,8 @@ #include #include +#include + /* CLASS IMPLEMENTATION ******************************************************/ namespace Cometa @@ -50,12 +53,12 @@ TransactionOutput::TransactionOutput(const Address& address, const Value& amount } cardano_transaction_output_t* value = nullptr; - const cardano_error_t result = cardano_transaction_output_new(addressCopy.checked(), 0U, &value); + const cardano_error_t result = cardano_transaction_output_new(checkedNativeHandle(addressCopy), 0U, &value); CardanoObject owner(value); checkCardanoError(result, "TransactionOutput"); - checkCardanoError(cardano_transaction_output_set_value(value, amountCopy.checked()), "TransactionOutput amount"); + checkCardanoError(cardano_transaction_output_set_value(value, checkedNativeHandle(amountCopy)), "TransactionOutput amount"); m_value = owner.release(); } @@ -88,7 +91,7 @@ TransactionOutput::fromCbor(const std::vector& cbor) { TransactionOutput value(*decodeCbor(cbor, cardano_transaction_output_from_cbor)); - value.validate(); + validateValue(value); return value; } @@ -105,7 +108,7 @@ TransactionOutput::address() const cardano_address_t* value = cardano_transaction_output_get_address(checked()); CardanoObject owner(value); - const Address component(*owner.release()); + const Address component = Address::adopt(owner.release()); return Address(component); } @@ -115,7 +118,7 @@ TransactionOutput::setAddress(const Address& value) { Address copy(value); - checkCardanoError(cardano_transaction_output_set_address(checked(), copy.checked()), "TransactionOutput setAddress"); + checkCardanoError(cardano_transaction_output_set_address(checked(), checkedNativeHandle(copy)), "TransactionOutput setAddress"); } Value @@ -124,7 +127,7 @@ TransactionOutput::amount() const cardano_value_t* value = cardano_transaction_output_get_value(checked()); CardanoObject owner(value); - const Value component(*owner.release()); + const Value component = Value::adopt(owner.release()); return Value(component); } @@ -139,7 +142,7 @@ TransactionOutput::setAmount(const Value& value) throw std::invalid_argument("Output lovelace must not be negative"); } - checkCardanoError(cardano_transaction_output_set_value(checked(), copy.checked()), "TransactionOutput setAmount"); + checkCardanoError(cardano_transaction_output_set_value(checked(), checkedNativeHandle(copy)), "TransactionOutput setAmount"); } std::optional @@ -153,7 +156,7 @@ TransactionOutput::datum() const return std::nullopt; } - const Datum component(*owner.release()); + const Datum component = Datum::adopt(owner.release()); return Datum(component); } @@ -163,7 +166,7 @@ TransactionOutput::setDatum(const std::optional& value) { std::optional copy(value); - checkCardanoError(cardano_transaction_output_set_datum(checked(), copy ? copy->checked() : nullptr), "TransactionOutput setDatum"); + checkCardanoError(cardano_transaction_output_set_datum(checked(), copy ? checkedNativeHandle(*copy) : nullptr), "TransactionOutput setDatum"); } std::optional