@layerzerolabs/protocol-stellar-v2 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +443 -302
- package/.turbo/turbo-lint.log +118 -96
- package/.turbo/turbo-test.log +853 -731
- package/Cargo.lock +120 -37
- package/Cargo.toml +8 -5
- package/contracts/common-macros/src/contract_impl.rs +44 -0
- package/contracts/common-macros/src/lib.rs +86 -40
- package/contracts/common-macros/src/ownable.rs +24 -32
- package/contracts/common-macros/src/storage.rs +95 -120
- package/contracts/common-macros/src/tests/contract_impl.rs +289 -0
- package/contracts/common-macros/src/tests/mod.rs +9 -0
- package/contracts/common-macros/src/tests/ownable.rs +151 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +85 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +30 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap +9 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +1072 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +45 -0
- package/contracts/common-macros/src/tests/storage.rs +485 -0
- package/contracts/common-macros/src/tests/test_helpers.rs +93 -0
- package/contracts/common-macros/src/tests/ttl_configurable.rs +34 -0
- package/contracts/common-macros/src/ttl_configurable.rs +31 -14
- package/contracts/common-macros/src/utils.rs +27 -0
- package/contracts/endpoint-v2/ARCHITECTURE.md +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +18 -15
- package/contracts/endpoint-v2/src/interfaces/message_lib.rs +2 -3
- package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +5 -3
- package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/send_lib.rs +4 -4
- package/contracts/endpoint-v2/src/lib.rs +6 -5
- package/contracts/endpoint-v2/src/message_lib_manager.rs +14 -6
- package/contracts/endpoint-v2/src/messaging_channel.rs +6 -2
- package/contracts/endpoint-v2/src/messaging_composer.rs +6 -2
- package/contracts/endpoint-v2/src/storage.rs +10 -7
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +16 -16
- package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +46 -46
- package/contracts/endpoint-v2/src/tests/mock.rs +2 -2
- package/contracts/endpoint-v2/src/util.rs +8 -2
- package/contracts/message-libs/block-message-lib/Cargo.toml +1 -0
- package/contracts/message-libs/block-message-lib/src/lib.rs +5 -5
- package/contracts/message-libs/message-lib-common/src/errors.rs +8 -8
- package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +0 -1
- package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +3 -3
- package/contracts/message-libs/message-lib-common/src/lib.rs +0 -2
- package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +4 -6
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +2 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +11 -11
- package/contracts/message-libs/message-lib-common/src/worker_options.rs +10 -16
- package/contracts/message-libs/simple-message-lib/src/errors.rs +0 -4
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +49 -34
- package/contracts/message-libs/simple-message-lib/src/storage.rs +3 -7
- package/contracts/message-libs/simple-message-lib/src/test.rs +3 -3
- package/contracts/message-libs/treasury/src/storage.rs +1 -2
- package/contracts/message-libs/treasury/src/tests/setup.rs +3 -2
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +0 -13
- package/contracts/message-libs/treasury/src/treasury.rs +18 -21
- package/contracts/message-libs/uln-302/Cargo.toml +1 -0
- package/contracts/message-libs/uln-302/src/interfaces/mod.rs +4 -4
- package/contracts/message-libs/uln-302/src/interfaces/{receive.rs → receive_uln.rs} +3 -3
- package/contracts/message-libs/uln-302/src/interfaces/{send.rs → send_uln.rs} +8 -80
- package/contracts/message-libs/uln-302/src/lib.rs +5 -4
- package/contracts/message-libs/uln-302/src/{receive.rs → receive_uln.rs} +20 -12
- package/contracts/message-libs/uln-302/src/{send.rs → send_uln.rs} +19 -13
- package/contracts/message-libs/uln-302/src/storage.rs +1 -2
- package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +3 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +30 -30
- package/contracts/message-libs/uln-302/src/tests/setup.rs +12 -11
- package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +1 -1
- package/contracts/message-libs/uln-302/src/{config_validation.rs → types.rs} +79 -11
- package/contracts/message-libs/uln-302/src/uln302.rs +15 -10
- package/contracts/oapp-macros/Cargo.toml +2 -8
- package/contracts/oapp-macros/src/lib.rs +57 -311
- package/contracts/oapp-macros/src/oapp_core.rs +23 -32
- package/contracts/oapp-macros/src/oapp_full.rs +8 -2
- package/contracts/oapp-macros/src/oapp_options_type3.rs +21 -36
- package/contracts/oapp-macros/src/oapp_receiver.rs +38 -57
- package/contracts/oapp-macros/src/oapp_sender.rs +12 -14
- package/contracts/oapp-macros/src/util.rs +14 -10
- package/contracts/oapps/counter/Cargo.toml +2 -1
- package/contracts/oapps/counter/integration_tests/utils.rs +4 -4
- package/contracts/oapps/counter/src/codec.rs +8 -9
- package/contracts/oapps/counter/src/counter.rs +156 -147
- package/contracts/oapps/counter/src/storage.rs +1 -2
- package/contracts/oapps/counter/src/tests/test_codec.rs +5 -5
- package/contracts/oapps/counter/src/tests/test_counter.rs +11 -13
- package/contracts/oapps/oapp/Cargo.toml +1 -0
- package/contracts/oapps/oapp/src/errors.rs +1 -1
- package/contracts/oapps/oapp/src/lib.rs +3 -0
- package/contracts/oapps/oapp/src/macro_tests/mod.rs +1 -0
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +312 -0
- package/contracts/oapps/oapp/src/oapp_core.rs +52 -53
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +18 -28
- package/contracts/oapps/oapp/src/oapp_receiver.rs +82 -31
- package/contracts/oapps/oapp/src/oapp_sender.rs +55 -13
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +16 -3
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +33 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +6 -9
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +28 -15
- package/contracts/oapps/oft/Cargo.toml +27 -0
- package/contracts/oapps/oft/integration-tests/mod.rs +3 -0
- package/contracts/oapps/oft/integration-tests/setup.rs +320 -0
- package/contracts/oapps/oft/integration-tests/test_with_sml.rs +155 -0
- package/contracts/oapps/oft/integration-tests/utils.rs +201 -0
- package/contracts/oapps/oft/src/codec/mod.rs +2 -0
- package/contracts/oapps/oft/src/codec/oft_compose_msg_codec.rs +55 -0
- package/contracts/oapps/oft/src/codec/oft_msg_codec.rs +62 -0
- package/contracts/oapps/oft/src/constants.rs +5 -0
- package/contracts/oapps/oft/src/errors.rs +8 -0
- package/contracts/oapps/oft/src/events.rs +19 -0
- package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +23 -0
- package/contracts/oapps/oft/src/interfaces/mod.rs +3 -0
- package/contracts/oapps/oft/src/lib.rs +22 -0
- package/contracts/oapps/oft/src/macro_tests/mod.rs +2 -0
- package/contracts/oapps/oft/src/macro_tests/test_all_default.rs +41 -0
- package/contracts/oapps/oft/src/macro_tests/test_override.rs +83 -0
- package/contracts/oapps/oft/src/oft.rs +320 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +50 -0
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +50 -0
- package/contracts/oapps/oft/src/oft_types/mod.rs +10 -0
- package/contracts/oapps/oft/src/storage.rs +11 -0
- package/contracts/oapps/oft/src/tests/mod.rs +13 -0
- package/contracts/oapps/oft/src/tests/test_decimals.rs +89 -0
- package/contracts/oapps/oft/src/tests/test_lz_receive.rs +282 -0
- package/contracts/oapps/oft/src/tests/test_oft_compose_msg_codec.rs +68 -0
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +136 -0
- package/contracts/oapps/oft/src/tests/test_oft_version.rs +13 -0
- package/contracts/oapps/oft/src/tests/test_quote_oft.rs +159 -0
- package/contracts/oapps/oft/src/tests/test_quote_send.rs +195 -0
- package/contracts/oapps/oft/src/tests/test_resolve_address.rs +37 -0
- package/contracts/oapps/oft/src/tests/test_send.rs +915 -0
- package/contracts/oapps/oft/src/tests/test_token.rs +47 -0
- package/contracts/oapps/oft/src/tests/test_utils.rs +789 -0
- package/contracts/oapps/oft/src/types.rs +38 -0
- package/contracts/oapps/oft/src/utils.rs +67 -0
- package/contracts/oapps/oft-mint-burn/Cargo.toml +26 -0
- package/contracts/oapps/oft-mint-burn/src/lib.rs +3 -0
- package/contracts/oapps/oft-mint-burn/src/oft.rs +28 -0
- package/contracts/oapps/oft-mint-burn/src/tests/mod.rs +1 -0
- package/contracts/utils/src/buffer_reader.rs +8 -9
- package/contracts/utils/src/buffer_writer.rs +11 -5
- package/contracts/utils/src/errors.rs +5 -5
- package/contracts/utils/src/ownable.rs +14 -6
- package/contracts/utils/src/testing_utils.rs +11 -1
- package/contracts/utils/src/tests/buffer_reader.rs +491 -730
- package/contracts/utils/src/tests/buffer_writer.rs +336 -148
- package/contracts/utils/src/tests/bytes_ext.rs +125 -40
- package/contracts/utils/src/tests/mod.rs +3 -0
- package/contracts/utils/src/tests/ownable.rs +379 -27
- package/contracts/utils/src/tests/test_helper.rs +47 -0
- package/contracts/utils/src/tests/testing_utils.rs +555 -0
- package/contracts/utils/src/tests/ttl.rs +421 -0
- package/contracts/utils/src/ttl.rs +29 -89
- package/contracts/workers/dvn/Cargo.toml +31 -0
- package/contracts/workers/dvn/src/auth.rs +66 -0
- package/contracts/workers/dvn/src/dvn.rs +143 -0
- package/contracts/workers/dvn/src/errors.rs +21 -0
- package/contracts/workers/dvn/src/events.rs +19 -0
- package/contracts/workers/dvn/src/interfaces/dvn.rs +12 -0
- package/contracts/workers/dvn/src/interfaces/mod.rs +5 -0
- package/contracts/workers/dvn/src/interfaces/multisig.rs +15 -0
- package/contracts/workers/dvn/src/lib.rs +24 -0
- package/contracts/workers/dvn/src/multisig.rs +127 -0
- package/contracts/workers/dvn/src/storage.rs +35 -0
- package/contracts/workers/dvn/src/tests/auth.rs +237 -0
- package/contracts/workers/dvn/src/tests/dvn.rs +349 -0
- package/contracts/workers/dvn/src/tests/key_pair.rs +66 -0
- package/contracts/workers/dvn/src/tests/mod.rs +5 -0
- package/contracts/workers/dvn/src/tests/multisig/mod.rs +3 -0
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +133 -0
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +108 -0
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +109 -0
- package/contracts/workers/dvn/src/tests/setup.rs +109 -0
- package/contracts/workers/dvn/src/types.rs +26 -0
- package/contracts/workers/dvn-fee-lib/Cargo.toml +24 -0
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +113 -0
- package/contracts/workers/dvn-fee-lib/src/errors.rs +8 -0
- package/contracts/workers/dvn-fee-lib/src/lib.rs +17 -0
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +282 -0
- package/contracts/workers/dvn-fee-lib/src/tests/mod.rs +1 -0
- package/contracts/workers/executor/Cargo.toml +10 -7
- package/contracts/workers/executor/src/errors.rs +8 -0
- package/contracts/workers/executor/src/events.rs +4 -7
- package/contracts/workers/executor/src/interfaces/executor.rs +72 -22
- package/contracts/workers/executor/src/interfaces/mod.rs +0 -2
- package/contracts/workers/executor/src/lib.rs +16 -7
- package/contracts/workers/executor/src/lz_executor.rs +308 -0
- package/contracts/workers/executor/src/storage.rs +24 -16
- package/contracts/workers/executor-fee-lib/Cargo.toml +22 -0
- package/contracts/workers/executor-fee-lib/src/errors.rs +15 -0
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +215 -0
- package/contracts/workers/executor-fee-lib/src/executor_option.rs +203 -0
- package/contracts/workers/executor-fee-lib/src/lib.rs +7 -0
- package/contracts/workers/executor-helper/Cargo.toml +29 -0
- package/contracts/workers/executor-helper/src/executor_helper.rs +161 -0
- package/contracts/workers/executor-helper/src/lib.rs +11 -0
- package/contracts/workers/{worker-common → worker}/Cargo.toml +1 -4
- package/contracts/workers/worker/src/errors.rs +24 -0
- package/contracts/workers/worker/src/events.rs +62 -0
- package/contracts/workers/worker/src/interfaces/dvn_fee_lib.rs +75 -0
- package/contracts/workers/worker/src/interfaces/executor_fee_lib.rs +84 -0
- package/contracts/workers/{worker-common → worker}/src/interfaces/mod.rs +2 -2
- package/contracts/workers/worker/src/interfaces/price_feed.rs +85 -0
- package/contracts/workers/worker/src/lib.rs +14 -0
- package/contracts/workers/worker/src/storage.rs +63 -0
- package/contracts/workers/worker/src/worker.rs +459 -0
- package/package.json +3 -3
- package/sdk/dist/generated/bml.d.ts +88 -17
- package/sdk/dist/generated/bml.js +62 -16
- package/sdk/dist/generated/counter.d.ts +281 -102
- package/sdk/dist/generated/counter.js +93 -41
- package/sdk/dist/generated/endpoint.d.ts +128 -105
- package/sdk/dist/generated/endpoint.js +47 -45
- package/sdk/dist/generated/sml.d.ts +212 -69
- package/sdk/dist/generated/sml.js +103 -53
- package/sdk/dist/generated/uln302.d.ts +270 -173
- package/sdk/dist/generated/uln302.js +112 -64
- package/sdk/package.json +11 -11
- package/sdk/test/index.test.ts +147 -42
- package/sdk/test/suites/constants.ts +7 -3
- package/sdk/test/suites/deploy.ts +65 -42
- package/sdk/test/suites/localnet.ts +2 -2
- package/sdk/test/suites/scan.ts +28 -25
- package/sdk/test/utils.ts +199 -0
- package/sdk/tsconfig.json +93 -95
- package/tools/ts-bindings-gen/src/main.rs +2 -0
- package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +0 -310
- package/contracts/common-macros/src/tests.rs +0 -287
- package/contracts/oapp-macros/tests/test_macros.rs +0 -522
- package/contracts/workers/executor/src/executor.rs +0 -347
- package/contracts/workers/executor/src/interfaces/types.rs +0 -51
- package/contracts/workers/worker-common/src/constants.rs +0 -17
- package/contracts/workers/worker-common/src/errors.rs +0 -6
- package/contracts/workers/worker-common/src/events.rs +0 -34
- package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +0 -35
- package/contracts/workers/worker-common/src/interfaces/price_feed.rs +0 -40
- package/contracts/workers/worker-common/src/interfaces/worker.rs +0 -60
- package/contracts/workers/worker-common/src/lib.rs +0 -19
- package/contracts/workers/worker-common/src/storage.rs +0 -32
- package/contracts/workers/worker-common/src/worker_common.rs +0 -166
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
//! # OApp Procedural Macros
|
|
2
2
|
//!
|
|
3
|
-
//! This crate provides procedural
|
|
4
|
-
//! functionality on Soroban smart contracts.
|
|
5
|
-
//! cross-chain applications by automatically generating the necessary trait implementations.
|
|
3
|
+
//! This crate provides the `#[oapp]` procedural macro for implementing LayerZero OApp
|
|
4
|
+
//! (Omnichain Application) functionality on Soroban smart contracts.
|
|
6
5
|
//!
|
|
7
6
|
//! ## Overview
|
|
8
7
|
//!
|
|
9
|
-
//! The OApp framework
|
|
8
|
+
//! The OApp framework provides full bidirectional cross-chain communication:
|
|
10
9
|
//!
|
|
11
|
-
//! - **OAppCore**: Foundation for all OApp functionality
|
|
10
|
+
//! - **OAppCore**: Foundation for all OApp functionality (peer management, endpoint access)
|
|
12
11
|
//! - **OAppSender**: Enables sending cross-chain messages through LayerZero
|
|
13
12
|
//! - **OAppReceiver**: Handles incoming cross-chain messages
|
|
14
13
|
//! - **OAppOptionsType3**: Manages enforced options for message execution parameters
|
|
@@ -16,21 +15,8 @@
|
|
|
16
15
|
//! ## Available Macros
|
|
17
16
|
//!
|
|
18
17
|
//! ### `#[oapp]`
|
|
19
|
-
//!
|
|
20
|
-
//!
|
|
21
|
-
//!
|
|
22
|
-
//! ### `#[oapp_core]`
|
|
23
|
-
//! Derives only the core OApp functionality (peer management, endpoint access).
|
|
24
|
-
//!
|
|
25
|
-
//! ### `#[oapp_sender]`
|
|
26
|
-
//! Derives Core + Sender functionality for applications that only need to send messages.
|
|
27
|
-
//!
|
|
28
|
-
//! ### `#[oapp_receiver]`
|
|
29
|
-
//! Derives Core + Receiver functionality for applications that only need to receive messages.
|
|
30
|
-
//!
|
|
31
|
-
//! ### `#[oapp_options_type3]`
|
|
32
|
-
//! Derives the Options Type 3 functionality for managing enforced message options.
|
|
33
|
-
//! Can be combined with other macros.
|
|
18
|
+
//! The main macro that provides Core + Sender + Receiver + OptionsType3 functionality.
|
|
19
|
+
//! This is the only macro you need for cross-chain communication.
|
|
34
20
|
//!
|
|
35
21
|
//! ### `#[oapp_manual_impl(...)]`
|
|
36
22
|
//! A marker attribute to indicate which trait implementations should be manually provided
|
|
@@ -38,28 +24,14 @@
|
|
|
38
24
|
//!
|
|
39
25
|
//! ## Manual Implementation Control
|
|
40
26
|
//!
|
|
41
|
-
//! By default,
|
|
27
|
+
//! By default, `#[oapp]` generates default trait implementations. Use `#[oapp_manual_impl(...)]`
|
|
42
28
|
//! to customize specific behaviors:
|
|
43
29
|
//!
|
|
44
|
-
//! ```ignore
|
|
45
|
-
//! #[oapp_core]
|
|
46
|
-
//! #[oapp_manual_impl(core)]
|
|
47
|
-
//! struct MyOApp;
|
|
48
|
-
//!
|
|
49
|
-
//! impl OAppCoreOverrides for MyOApp {
|
|
50
|
-
//! fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
51
|
-
//! (1, 1) // Custom version
|
|
52
|
-
//! }
|
|
53
|
-
//! }
|
|
54
|
-
//! ```
|
|
55
|
-
//!
|
|
56
30
|
//! Supported options:
|
|
57
|
-
//! - `core` - Manually implement `
|
|
58
|
-
//! - `sender` - Manually implement `
|
|
59
|
-
//! - `
|
|
60
|
-
//!
|
|
61
|
-
//! **Note**: There is no `receiver` option because `OAppReceiverOverrides::__lz_receive`
|
|
62
|
-
//! **must always** be manually implemented by the user to define custom message handling logic.
|
|
31
|
+
//! - `core` - Manually implement `OAppCore`
|
|
32
|
+
//! - `sender` - Manually implement `OAppSender`
|
|
33
|
+
//! - `receiver` - Manually implement `OAppReceiver` (useful for custom `next_nonce`, etc.)
|
|
34
|
+
//! - `options_type3` - Manually implement `OAppOptionsType3`
|
|
63
35
|
//!
|
|
64
36
|
//! ## Examples
|
|
65
37
|
//!
|
|
@@ -67,13 +39,12 @@
|
|
|
67
39
|
//!
|
|
68
40
|
//! ```ignore
|
|
69
41
|
//! use oapp_macros::oapp;
|
|
70
|
-
//! use oapp::oapp_receiver::OAppReceiverOverrides;
|
|
71
42
|
//!
|
|
72
43
|
//! #[oapp]
|
|
73
44
|
//! struct MyOApp;
|
|
74
45
|
//!
|
|
75
|
-
//! // Only __lz_receive must be implemented
|
|
76
|
-
//! impl
|
|
46
|
+
//! // Only __lz_receive must be implemented as an inherent method
|
|
47
|
+
//! impl MyOApp {
|
|
77
48
|
//! fn __lz_receive(
|
|
78
49
|
//! env: &Env,
|
|
79
50
|
//! executor: &Address,
|
|
@@ -83,49 +54,70 @@
|
|
|
83
54
|
//! extra_data: &Bytes,
|
|
84
55
|
//! value: i128,
|
|
85
56
|
//! ) {
|
|
86
|
-
//! // Your
|
|
57
|
+
//! // Your message handling logic (verify_and_clear_payload already called)
|
|
87
58
|
//! }
|
|
88
59
|
//! }
|
|
89
60
|
//! ```
|
|
90
61
|
//!
|
|
91
|
-
//! ###
|
|
62
|
+
//! ### OApp with Custom Core Version
|
|
92
63
|
//!
|
|
93
64
|
//! ```ignore
|
|
94
65
|
//! #[oapp]
|
|
95
66
|
//! #[oapp_manual_impl(core)]
|
|
96
|
-
//! struct
|
|
67
|
+
//! struct MyOApp;
|
|
97
68
|
//!
|
|
98
|
-
//!
|
|
99
|
-
//!
|
|
100
|
-
//!
|
|
69
|
+
//! #[contractimpl(contracttrait)]
|
|
70
|
+
//! #[common_macros::ownable]
|
|
71
|
+
//! impl OAppCore for MyOApp {
|
|
72
|
+
//! fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
73
|
+
//! (1, 1) // Custom version
|
|
101
74
|
//! }
|
|
102
|
-
//! // Other methods use defaults
|
|
103
75
|
//! }
|
|
104
76
|
//!
|
|
105
|
-
//! impl
|
|
77
|
+
//! impl MyOApp {
|
|
106
78
|
//! fn __lz_receive(...) { /* ... */ }
|
|
107
79
|
//! }
|
|
108
80
|
//! ```
|
|
109
81
|
//!
|
|
110
|
-
//! ###
|
|
82
|
+
//! ### OApp with Custom Receiver (e.g., ordered delivery)
|
|
111
83
|
//!
|
|
112
84
|
//! ```ignore
|
|
113
|
-
//!
|
|
114
|
-
//!
|
|
115
|
-
//!
|
|
85
|
+
//! use oapp::oapp_receiver::{OAppReceiver, verify_and_clear_payload};
|
|
86
|
+
//!
|
|
87
|
+
//! #[oapp]
|
|
88
|
+
//! #[oapp_manual_impl(receiver)]
|
|
89
|
+
//! struct MyOrderedOApp;
|
|
90
|
+
//!
|
|
91
|
+
//! #[contractimpl(contracttrait)]
|
|
92
|
+
//! impl OAppReceiver for MyOrderedOApp {
|
|
93
|
+
//! fn next_nonce(env: &Env, src_eid: u32, sender: &BytesN<32>) -> u64 {
|
|
94
|
+
//! // Custom nonce logic for ordered delivery
|
|
95
|
+
//! Storage::max_received_nonce(env, src_eid, sender) + 1
|
|
96
|
+
//! }
|
|
97
|
+
//! fn lz_receive(env: &Env, executor: &Address, origin: &Origin, ...) {
|
|
98
|
+
//! verify_and_clear_payload::<Self>(env, executor, origin, guid, message, value);
|
|
99
|
+
//! // Your message handling logic
|
|
100
|
+
//! }
|
|
101
|
+
//! }
|
|
116
102
|
//! ```
|
|
117
103
|
//!
|
|
118
|
-
//! ### OApp with
|
|
104
|
+
//! ### OApp with Multiple Manual Implementations
|
|
119
105
|
//!
|
|
120
106
|
//! ```ignore
|
|
121
107
|
//! #[oapp]
|
|
122
|
-
//! #[
|
|
123
|
-
//! struct
|
|
108
|
+
//! #[oapp_manual_impl(core, sender, options_type3)]
|
|
109
|
+
//! struct MyCustomOApp;
|
|
110
|
+
//!
|
|
111
|
+
//! #[contractimpl(contracttrait)]
|
|
112
|
+
//! #[common_macros::ownable]
|
|
113
|
+
//! impl OAppCore for MyCustomOApp { /* ... */ }
|
|
114
|
+
//! impl OAppSender for MyCustomOApp { /* ... */ }
|
|
115
|
+
//! #[contractimpl(contracttrait)]
|
|
116
|
+
//! impl OAppOptionsType3 for MyCustomOApp { /* ... */ }
|
|
124
117
|
//!
|
|
125
|
-
//! impl
|
|
118
|
+
//! impl MyCustomOApp {
|
|
126
119
|
//! fn __lz_receive(...) { /* ... */ }
|
|
127
120
|
//! }
|
|
128
|
-
//! // OAppOptionsType3Overrides uses defaults
|
|
129
121
|
//! ```
|
|
130
122
|
|
|
131
123
|
use crate::util::parse_struct;
|
|
@@ -138,162 +130,9 @@ mod oapp_receiver;
|
|
|
138
130
|
mod oapp_sender;
|
|
139
131
|
mod util;
|
|
140
132
|
|
|
141
|
-
/// Derives
|
|
133
|
+
/// Derives a complete OApp: `#[contract]` + `#[ownable]` + Core + Sender + Receiver + OptionsType3.
|
|
142
134
|
///
|
|
143
|
-
///
|
|
144
|
-
/// - `#[soroban_sdk::contract]` attribute
|
|
145
|
-
/// - `#[common_macros::ownable]` attribute for ownership management
|
|
146
|
-
/// - Implementation of `OAppCore` trait with methods delegating to `OAppCoreOverrides`
|
|
147
|
-
///
|
|
148
|
-
/// By default, an empty `OAppCoreOverrides` implementation is generated. Use
|
|
149
|
-
/// `#[oapp_manual_impl(core)]` to provide custom implementations.
|
|
150
|
-
///
|
|
151
|
-
/// # Example
|
|
152
|
-
///
|
|
153
|
-
/// ```ignore
|
|
154
|
-
/// #[oapp_core]
|
|
155
|
-
/// struct MyOApp;
|
|
156
|
-
/// // Uses default OAppCore implementation
|
|
157
|
-
/// ```
|
|
158
|
-
///
|
|
159
|
-
/// # Example with Manual Implementation
|
|
160
|
-
///
|
|
161
|
-
/// ```ignore
|
|
162
|
-
/// #[oapp_core]
|
|
163
|
-
/// #[oapp_manual_impl(core)]
|
|
164
|
-
/// struct MyCustomOApp;
|
|
165
|
-
///
|
|
166
|
-
/// impl OAppCoreOverrides for MyCustomOApp {
|
|
167
|
-
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
168
|
-
/// (1, 2)
|
|
169
|
-
/// }
|
|
170
|
-
/// }
|
|
171
|
-
/// ```
|
|
172
|
-
#[proc_macro_attribute]
|
|
173
|
-
pub fn oapp_core(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
174
|
-
let (name, item, disable_config) = match parse_struct(item) {
|
|
175
|
-
Ok(result) => result,
|
|
176
|
-
Err(e) => return e,
|
|
177
|
-
};
|
|
178
|
-
oapp_core::generate_impl(&name, item, disable_config.core).into()
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/// Derives OAppSender implementation, providing cross-chain message sending capabilities.
|
|
182
|
-
///
|
|
183
|
-
/// This macro automatically includes `#[oapp_core]` functionality, generating both
|
|
184
|
-
/// Core and Sender implementations. By default, an empty `OAppSenderOverrides`
|
|
185
|
-
/// implementation is generated. Use `#[oapp_manual_impl(sender)]` or
|
|
186
|
-
/// `#[oapp_manual_impl(core, sender)]` for custom implementations.
|
|
187
|
-
///
|
|
188
|
-
/// # Example
|
|
189
|
-
///
|
|
190
|
-
/// ```ignore
|
|
191
|
-
/// #[oapp_sender]
|
|
192
|
-
/// struct MySender;
|
|
193
|
-
/// // Can now send cross-chain messages using default implementations
|
|
194
|
-
/// ```
|
|
195
|
-
///
|
|
196
|
-
/// # Example with Manual Sender Implementation
|
|
197
|
-
///
|
|
198
|
-
/// ```ignore
|
|
199
|
-
/// #[oapp_sender]
|
|
200
|
-
/// #[oapp_manual_impl(sender)]
|
|
201
|
-
/// struct MyCustomSender;
|
|
202
|
-
///
|
|
203
|
-
/// impl OAppSenderOverrides for MyCustomSender {
|
|
204
|
-
/// // Custom sender logic
|
|
205
|
-
/// }
|
|
206
|
-
/// ```
|
|
207
|
-
#[proc_macro_attribute]
|
|
208
|
-
pub fn oapp_sender(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
209
|
-
let (name, item, disable_config) = match parse_struct(item) {
|
|
210
|
-
Ok(result) => result,
|
|
211
|
-
Err(e) => return e,
|
|
212
|
-
};
|
|
213
|
-
oapp_sender::generate_impl_with_core(&name, item, disable_config).into()
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/// Derives OAppReceiver implementation, providing receive capabilities
|
|
217
|
-
///
|
|
218
|
-
/// **Important**: Unlike other OApp macros, this macro does NOT support `manual_impl`
|
|
219
|
-
/// configuration because the `__lz_receive` method in `OAppReceiverOverrides` trait
|
|
220
|
-
/// has no default implementation. Users **MUST** always manually implement
|
|
221
|
-
/// `OAppReceiverOverrides::__lz_receive` to define their custom message handling logic.
|
|
222
|
-
///
|
|
223
|
-
/// # Example
|
|
224
|
-
/// ```ignore
|
|
225
|
-
/// #[oapp_receiver]
|
|
226
|
-
/// struct MyReceiver;
|
|
227
|
-
///
|
|
228
|
-
/// impl OAppReceiverOverrides for MyReceiver {
|
|
229
|
-
/// fn __lz_receive(
|
|
230
|
-
/// env: &Env,
|
|
231
|
-
/// executor: &Address,
|
|
232
|
-
/// origin: &Origin,
|
|
233
|
-
/// guid: &BytesN<32>,
|
|
234
|
-
/// message: &Bytes,
|
|
235
|
-
/// extra_data: &Bytes,
|
|
236
|
-
/// value: i128,
|
|
237
|
-
/// ) {
|
|
238
|
-
/// // Your custom message handling logic here
|
|
239
|
-
/// }
|
|
240
|
-
/// }
|
|
241
|
-
/// ```
|
|
242
|
-
#[proc_macro_attribute]
|
|
243
|
-
pub fn oapp_receiver(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
244
|
-
let (name, item, disable_config) = match parse_struct(item) {
|
|
245
|
-
Ok(result) => result,
|
|
246
|
-
Err(e) => return e,
|
|
247
|
-
};
|
|
248
|
-
oapp_receiver::generate_impl_with_core(&name, item, disable_config).into()
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/// Derives a complete OApp implementation with Core + Sender + Receiver functionality.
|
|
252
|
-
///
|
|
253
|
-
/// This is a convenience macro that combines all three core OApp components. It's the
|
|
254
|
-
/// most common choice for applications that need full bidirectional cross-chain communication.
|
|
255
|
-
///
|
|
256
|
-
/// **Important**: You **must** always implement `OAppReceiverOverrides::__lz_receive` to
|
|
257
|
-
/// define your custom message handling logic, as it has no default implementation.
|
|
258
|
-
///
|
|
259
|
-
/// # Example
|
|
260
|
-
///
|
|
261
|
-
/// ```ignore
|
|
262
|
-
/// #[oapp]
|
|
263
|
-
/// struct MyFullOApp;
|
|
264
|
-
///
|
|
265
|
-
/// impl OAppReceiverOverrides for MyFullOApp {
|
|
266
|
-
/// fn __lz_receive(
|
|
267
|
-
/// env: &Env,
|
|
268
|
-
/// executor: &Address,
|
|
269
|
-
/// origin: &Origin,
|
|
270
|
-
/// guid: &BytesN<32>,
|
|
271
|
-
/// message: &Bytes,
|
|
272
|
-
/// extra_data: &Bytes,
|
|
273
|
-
/// value: i128,
|
|
274
|
-
/// ) {
|
|
275
|
-
/// // Your message handling logic here
|
|
276
|
-
/// }
|
|
277
|
-
/// }
|
|
278
|
-
/// ```
|
|
279
|
-
///
|
|
280
|
-
/// # Example with Manual Core Implementation
|
|
281
|
-
///
|
|
282
|
-
/// ```ignore
|
|
283
|
-
/// #[oapp]
|
|
284
|
-
/// #[oapp_manual_impl(core)]
|
|
285
|
-
/// struct MyCustomFullOApp;
|
|
286
|
-
///
|
|
287
|
-
/// impl OAppCoreOverrides for MyCustomFullOApp {
|
|
288
|
-
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
289
|
-
/// (2, 0)
|
|
290
|
-
/// }
|
|
291
|
-
/// }
|
|
292
|
-
///
|
|
293
|
-
/// impl OAppReceiverOverrides for MyCustomFullOApp {
|
|
294
|
-
/// fn __lz_receive(...) { /* ... */ }
|
|
295
|
-
/// }
|
|
296
|
-
/// ```
|
|
135
|
+
/// You must implement `__lz_receive` as an inherent method. See module docs for examples.
|
|
297
136
|
#[proc_macro_attribute]
|
|
298
137
|
pub fn oapp(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
299
138
|
let (name, item, disable_config) = match parse_struct(item) {
|
|
@@ -303,105 +142,12 @@ pub fn oapp(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
303
142
|
oapp_full::generate_impl(&name, item, disable_config).into()
|
|
304
143
|
}
|
|
305
144
|
|
|
306
|
-
///
|
|
307
|
-
///
|
|
308
|
-
/// This macro provides fine-grained control over message execution parameters per endpoint
|
|
309
|
-
/// and message type. Unlike other OApp macros, this does **not** automatically add the
|
|
310
|
-
/// `#[soroban_sdk::contract]` attribute, so it can be used standalone or combined with
|
|
311
|
-
/// other OApp macros.
|
|
312
|
-
///
|
|
313
|
-
/// By default, an empty `OAppOptionsType3Overrides` implementation is generated. Use
|
|
314
|
-
/// `#[oapp_manual_impl(options_type3)]` for custom implementations.
|
|
315
|
-
///
|
|
316
|
-
/// # Example - Standalone
|
|
317
|
-
///
|
|
318
|
-
/// ```ignore
|
|
319
|
-
/// #[contract]
|
|
320
|
-
/// #[ownable]
|
|
321
|
-
/// #[oapp_options_type3]
|
|
322
|
-
/// struct MyOptions;
|
|
323
|
-
/// // Uses default options implementation
|
|
324
|
-
/// ```
|
|
325
|
-
///
|
|
326
|
-
/// # Example - Combined with Full OApp
|
|
327
|
-
///
|
|
328
|
-
/// ```ignore
|
|
329
|
-
/// #[oapp]
|
|
330
|
-
/// #[oapp_options_type3]
|
|
331
|
-
/// struct MyOAppWithOptions;
|
|
332
|
-
///
|
|
333
|
-
/// impl OAppReceiverOverrides for MyOAppWithOptions {
|
|
334
|
-
/// fn __lz_receive(...) { /* ... */ }
|
|
335
|
-
/// }
|
|
336
|
-
/// ```
|
|
337
|
-
///
|
|
338
|
-
/// # Example with Manual Implementation
|
|
339
|
-
///
|
|
340
|
-
/// ```ignore
|
|
341
|
-
/// #[contract]
|
|
342
|
-
/// #[ownable]
|
|
343
|
-
/// #[oapp_options_type3]
|
|
344
|
-
/// #[oapp_manual_impl(options_type3)]
|
|
345
|
-
/// struct MyCustomOptions;
|
|
346
|
-
///
|
|
347
|
-
/// impl OAppOptionsType3Overrides for MyCustomOptions {
|
|
348
|
-
/// fn __enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes {
|
|
349
|
-
/// // Custom enforced options logic
|
|
350
|
-
/// }
|
|
351
|
-
/// }
|
|
352
|
-
/// ```
|
|
353
|
-
#[proc_macro_attribute]
|
|
354
|
-
pub fn oapp_options_type3(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
355
|
-
let (name, item, disable_config) = match parse_struct(item) {
|
|
356
|
-
Ok(result) => result,
|
|
357
|
-
Err(e) => return e,
|
|
358
|
-
};
|
|
359
|
-
oapp_options_type3::generate_impl(&name, item, disable_config.options_type3).into()
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/// Marker attribute to specify which trait implementations should be manually provided.
|
|
363
|
-
///
|
|
364
|
-
/// Use this attribute together with OApp macros to indicate that you will provide
|
|
365
|
-
/// custom implementations instead of using the default ones.
|
|
366
|
-
///
|
|
367
|
-
/// # Supported Options
|
|
368
|
-
///
|
|
369
|
-
/// - `core` - Manually implement `OAppCoreOverrides`
|
|
370
|
-
/// - `sender` - Manually implement `OAppSenderOverrides`
|
|
371
|
-
/// - `options_type3` - Manually implement `OAppOptionsType3Overrides`
|
|
372
|
-
///
|
|
373
|
-
/// **Note**: There is no `receiver` option because `OAppReceiverOverrides::__lz_receive`
|
|
374
|
-
/// must **always** be manually implemented (it has no default implementation).
|
|
375
|
-
///
|
|
376
|
-
/// # Examples
|
|
377
|
-
///
|
|
378
|
-
/// ```ignore
|
|
379
|
-
/// // Manual core implementation
|
|
380
|
-
/// #[oapp_core]
|
|
381
|
-
/// #[oapp_manual_impl(core)]
|
|
382
|
-
/// struct MyOApp;
|
|
383
|
-
///
|
|
384
|
-
/// impl OAppCoreOverrides for MyOApp {
|
|
385
|
-
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
386
|
-
/// (1, 1)
|
|
387
|
-
/// }
|
|
388
|
-
/// }
|
|
389
|
-
/// ```
|
|
145
|
+
/// Marker attribute to skip generating specific trait implementations.
|
|
390
146
|
///
|
|
391
|
-
///
|
|
392
|
-
/// // Multiple manual implementations
|
|
393
|
-
/// #[oapp]
|
|
394
|
-
/// #[oapp_options_type3]
|
|
395
|
-
/// #[oapp_manual_impl(core, sender, options_type3)]
|
|
396
|
-
/// struct MyFullCustomOApp;
|
|
147
|
+
/// Supported options: `core`, `sender`, `receiver`, `options_type3`
|
|
397
148
|
///
|
|
398
|
-
///
|
|
399
|
-
///
|
|
400
|
-
/// impl OAppReceiverOverrides for MyFullCustomOApp {
|
|
401
|
-
/// fn __lz_receive(...) { /* required */ }
|
|
402
|
-
/// }
|
|
403
|
-
/// impl OAppOptionsType3Overrides for MyFullCustomOApp { /* ... */ }
|
|
404
|
-
/// ```
|
|
149
|
+
/// Example: `#[oapp_manual_impl(core, receiver)]` skips generating
|
|
150
|
+
/// `OAppCore` and `OAppReceiver` implementations.
|
|
405
151
|
#[proc_macro_attribute]
|
|
406
152
|
pub fn oapp_manual_impl(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
407
153
|
item
|
|
@@ -1,49 +1,40 @@
|
|
|
1
|
+
use heck::ToSnakeCase;
|
|
1
2
|
use proc_macro2::TokenStream;
|
|
2
3
|
use quote::quote;
|
|
3
4
|
use syn::{Ident, ItemStruct};
|
|
4
5
|
|
|
6
|
+
/// Generates the `OAppCore` trait implementation and adds `#[contract]` + `#[ownable]` to the struct.
|
|
7
|
+
///
|
|
8
|
+
/// When `manual_impl_core` is false, generates an empty `impl OAppCore`
|
|
9
|
+
/// that uses the trait's default implementations for peer management and endpoint access.
|
|
5
10
|
pub fn generate_impl(name: &Ident, item_struct: ItemStruct, manual_impl_core: bool) -> TokenStream {
|
|
11
|
+
// Create a unique module name to avoid import conflicts when multiple structs
|
|
12
|
+
// use oapp macros in the same module. The import must be `OAppCore`
|
|
13
|
+
// (not an alias) because Soroban SDK's #[contractimpl(contracttrait)] generates
|
|
14
|
+
// a macro call `OAppCore!(...)` that needs to resolve to the macro
|
|
15
|
+
// exported by #[contracttrait].
|
|
16
|
+
let impl_mod = syn::Ident::new(&format!("__oapp_impl_{}", name.to_string().to_snake_case()), name.span());
|
|
17
|
+
|
|
6
18
|
let manual_impl = (!manual_impl_core).then(|| {
|
|
7
19
|
quote! {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
#[doc(hidden)]
|
|
21
|
+
mod #impl_mod {
|
|
22
|
+
use super::*;
|
|
23
|
+
// Import types used by OAppCore trait's default implementations
|
|
24
|
+
use soroban_sdk::{Address, BytesN, Env};
|
|
25
|
+
use oapp::oapp_core::OAppCore;
|
|
26
|
+
|
|
27
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
28
|
+
impl OAppCore for #name {}
|
|
29
|
+
}
|
|
11
30
|
}
|
|
12
31
|
});
|
|
13
32
|
|
|
14
33
|
quote! {
|
|
15
|
-
use oapp::oapp_core::OAppCore as _;
|
|
16
|
-
|
|
17
|
-
#[soroban_sdk::contract]
|
|
18
34
|
#[common_macros::ownable]
|
|
35
|
+
#[soroban_sdk::contract]
|
|
19
36
|
#item_struct
|
|
20
37
|
|
|
21
|
-
#[soroban_sdk::contractimpl]
|
|
22
|
-
impl oapp::oapp_core::OAppCore for #name {
|
|
23
|
-
#[common_macros::only_owner]
|
|
24
|
-
fn set_peer(env: &soroban_sdk::Env, eid: u32, peer: &Option<soroban_sdk::BytesN<32>>) {
|
|
25
|
-
<Self as oapp::oapp_core::OAppCoreOverrides>::__set_peer(env, eid, peer)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
#[common_macros::only_owner]
|
|
29
|
-
fn set_delegate(env: &soroban_sdk::Env, delegate: &Option<soroban_sdk::Address>) {
|
|
30
|
-
<Self as oapp::oapp_core::OAppCoreOverrides>::__set_delegate(env, delegate)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
fn peer(env: &soroban_sdk::Env, eid: u32) -> Option<soroban_sdk::BytesN<32>> {
|
|
34
|
-
<Self as oapp::oapp_core::OAppCoreOverrides>::__peer(env, eid)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fn oapp_version(env: &soroban_sdk::Env) -> (u64, u64) {
|
|
38
|
-
<Self as oapp::oapp_core::OAppCoreOverrides>::__oapp_version(env)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fn endpoint(env: &soroban_sdk::Env) -> soroban_sdk::Address {
|
|
42
|
-
<Self as oapp::oapp_core::OAppCoreOverrides>::__endpoint(env)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
38
|
#manual_impl
|
|
48
39
|
}
|
|
49
40
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
use crate::{oapp_core, oapp_receiver, oapp_sender, util::ManualImplConfig};
|
|
1
|
+
use crate::{oapp_core, oapp_options_type3, oapp_receiver, oapp_sender, util::ManualImplConfig};
|
|
2
2
|
use proc_macro2::TokenStream;
|
|
3
3
|
use quote::quote;
|
|
4
4
|
use syn::{Ident, ItemStruct};
|
|
5
5
|
|
|
6
|
+
/// Generates the full OApp implementation: Core + Sender + Receiver + OptionsType3.
|
|
7
|
+
///
|
|
8
|
+
/// Combines all OApp components. Use `manual_impl_config` to skip generating
|
|
9
|
+
/// specific trait implementations when custom implementations are needed.
|
|
6
10
|
pub fn generate_impl(name: &Ident, item: ItemStruct, manual_impl_config: ManualImplConfig) -> TokenStream {
|
|
7
11
|
let core_impl = oapp_core::generate_impl(name, item, manual_impl_config.core);
|
|
8
12
|
let sender_impl = oapp_sender::generate_impl(name, manual_impl_config.sender);
|
|
9
|
-
let receiver_impl = oapp_receiver::generate_impl(name);
|
|
13
|
+
let receiver_impl = oapp_receiver::generate_impl(name, manual_impl_config.receiver);
|
|
14
|
+
let options_type3_impl = oapp_options_type3::generate_impl(name, manual_impl_config.options_type3);
|
|
10
15
|
quote! {
|
|
11
16
|
#core_impl
|
|
12
17
|
#sender_impl
|
|
13
18
|
#receiver_impl
|
|
19
|
+
#options_type3_impl
|
|
14
20
|
}
|
|
15
21
|
}
|
|
@@ -1,46 +1,31 @@
|
|
|
1
|
+
use heck::ToSnakeCase;
|
|
1
2
|
use proc_macro2::TokenStream;
|
|
2
3
|
use quote::quote;
|
|
3
|
-
use syn::
|
|
4
|
+
use syn::Ident;
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/// Generates the `OAppOptionsType3` trait implementation.
|
|
7
|
+
///
|
|
8
|
+
/// When `manual_impl_options_type3` is false, generates an empty `impl OAppOptionsType3`
|
|
9
|
+
/// that uses the trait's default implementations for enforced options management.
|
|
10
|
+
pub fn generate_impl(name: &Ident, manual_impl_options_type3: bool) -> TokenStream {
|
|
11
|
+
let impl_mod =
|
|
12
|
+
syn::Ident::new(&format!("__oapp_options_type3_impl_{}", name.to_string().to_snake_case()), name.span());
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
let options_type3_impl = (!manual_impl_options_type3).then(|| {
|
|
15
|
+
quote! {
|
|
16
|
+
#[doc(hidden)]
|
|
17
|
+
mod #impl_mod {
|
|
18
|
+
use super::*;
|
|
19
|
+
use soroban_sdk::{Env, Bytes, Vec};
|
|
20
|
+
use oapp::oapp_options_type3::{OAppOptionsType3, EnforcedOptionParam};
|
|
21
|
+
|
|
22
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
23
|
+
impl OAppOptionsType3 for #name {}
|
|
24
|
+
}
|
|
11
25
|
}
|
|
12
26
|
});
|
|
13
27
|
|
|
14
28
|
quote! {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#item_struct
|
|
18
|
-
|
|
19
|
-
#[soroban_sdk::contractimpl]
|
|
20
|
-
impl oapp::oapp_options_type3::OAppOptionsType3 for #name
|
|
21
|
-
{
|
|
22
|
-
#[common_macros::only_owner]
|
|
23
|
-
fn set_enforced_options(
|
|
24
|
-
env: &soroban_sdk::Env,
|
|
25
|
-
options: soroban_sdk::Vec<oapp::oapp_options_type3::EnforcedOptionParam>,
|
|
26
|
-
) {
|
|
27
|
-
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__set_enforced_options(env, options)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fn combine_options(
|
|
31
|
-
env: &soroban_sdk::Env,
|
|
32
|
-
eid: u32,
|
|
33
|
-
msg_type: u32,
|
|
34
|
-
extra_options: &soroban_sdk::Bytes,
|
|
35
|
-
) -> soroban_sdk::Bytes {
|
|
36
|
-
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__combine_options(env, eid, msg_type, extra_options)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fn enforced_options(env: &soroban_sdk::Env, eid: u32, msg_type: u32) -> soroban_sdk::Bytes {
|
|
40
|
-
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__enforced_options(env, eid, msg_type)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
#manual_impl
|
|
29
|
+
#options_type3_impl
|
|
45
30
|
}
|
|
46
31
|
}
|