interactor - standard connection & wallet configs#2394
Draft
andrei-marinica wants to merge 28 commits into
Draft
interactor - standard connection & wallet configs#2394andrei-marinica wants to merge 28 commits into
andrei-marinica wants to merge 28 commits into
Conversation
|
Contract comparison - from 0406270 to ab1a2f3
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes how snippet-based interactors are configured and initialized by introducing reusable connection/wallet config types and a fluent HTTP interactor builder, then migrates the adder example interactor to the new approach.
Changes:
- Added
Wallet::to_bech32()(HRP-aware) andtest_wallets::by_name()to support config-driven wallet selection. - Introduced
multiversx-sc-snippetsconfig module (ConnectionConfig,WalletConfig,InteractorConfig) plusAutoSavestate persistence andHttpInteractorBuilder. - Refactored the
contracts/examples/adder/interactorexample to load config/state via the new builder and TOML config structure.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/core/src/wallet/wallet_impl.rs | Adds to_bech32() for HRP-aware Bech32 address encoding based on wallet source. |
| sdk/core/src/test_wallets.rs | Adds by_name() helper to resolve built-in test wallets dynamically. |
| framework/snippets/src/lib.rs | Exposes new config module and reexports HttpInteractorBuilder under the http feature. |
| framework/snippets/src/interactor/interactor_base.rs | Adds load_state() returning AutoSave<State> backed by state.toml. |
| framework/snippets/src/imports.rs | Reexports new config types and HttpInteractorBuilder in the snippets import prelude. |
| framework/snippets/src/http_interactor_builder.rs | New fluent builder to load config, connect, register wallets, and seed simulator blocks. |
| framework/snippets/src/config/wallet_config.rs | New serde-deserializable wallet config with caching and address derivation. |
| framework/snippets/src/config/interactor_config.rs | New trait for contract-specific configs to define connection + wallet registration. |
| framework/snippets/src/config/connection_config.rs | New connection config + chain type abstraction (real vs simulator). |
| framework/snippets/src/config/auto_save.rs | New RAII autosave wrapper that persists TOML on drop (optional no-save mode). |
| framework/snippets/src/config.rs | New config module aggregator/reexports. |
| framework/snippets/Cargo.toml | Adds serde and toml dependencies needed by the new config system. |
| contracts/examples/adder/interactor/tests/basic_interactor_cs_test.rs | Updates tests to construct interactors via HttpInteractorBuilder + typed config. |
| contracts/examples/adder/interactor/src/basic_interactor.rs | Refactors example interactor to use typed config, builder setup, and AutoSave state. |
| contracts/examples/adder/interactor/src/basic_interactor_state.rs | Removes bespoke state file persistence in favor of shared AutoSave. |
| contracts/examples/adder/interactor/src/basic_interactor_config.rs | Removes bespoke config loader/types in favor of shared config module + builder. |
| contracts/examples/adder/interactor/config.toml | Updates TOML structure to include contract_path, [connection], [owner], [wallet]. |
| Cargo.lock | Locks new dependency additions (serde, toml). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 69 out of 70 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
contracts/feature-tests/composability/forwarder-blind/dex-interactor/src/dex_interactor.rs:133
State::load_state()/Dropinstate.rsread/writedeploy.tomlrelative to the process working directory. This interactor now setsInteractorBase::current_dirviawith_current_dir(env!("CARGO_MANIFEST_DIR")), but that does not affect wheredeploy.tomlis persisted, so state may end up in an unexpected directory when run from a different CWD.
ContractInteract {
interactor,
wallet_addresses,
config,
state: State::load_state(),
}
Comment on lines
+67
to
+82
| fn load_wallet(&self) -> Wallet { | ||
| if let Some(name) = &self.test_wallet { | ||
| test_wallets::by_name(name.as_str()) | ||
| .unwrap_or_else(|| panic!("unknown test wallet name: '{name}'")) | ||
| } else if let Some(pem) = &self.pem { | ||
| Wallet::from_pem_file(pem).expect("failed to load PEM wallet") | ||
| } else if let Some(keyfile) = &self.keyfile { | ||
| let password = self | ||
| .keystore_password | ||
| .as_deref() | ||
| .expect("keystore_password is required when using keyfile"); | ||
| let keystore = Keystore::from_file(keyfile).expect("failed to load keystore file"); | ||
| keystore | ||
| .decrypt_wallet(password) | ||
| .expect("failed to decrypt wallet") | ||
| } else { |
Comment on lines
+1
to
4
| [connection] | ||
| chain_type = 'real' | ||
| gateway_uri = 'https://testnet-gateway.multiversx.com' | ||
| gateway_uri = 'https://devnet-gateway.multiversx.com' | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.