-
Notifications
You must be signed in to change notification settings - Fork 7
feat: app factory #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: app factory #248
Conversation
6a166c7 to
6d27d07
Compare
30ec996 to
ae01c00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces an app factory pattern for Algorand application deployment in the Rust crate, following the established patterns from Python and TypeScript implementations. The factory provides a high-level interface for creating, updating, and deploying applications using ARC-56 specifications.
Key changes:
- New
AppFactorystruct with fluent API for application lifecycle management - Integration with existing
AppDeployerfor idempotent deployment operations - Enhanced
AlgorandClientwith persistent app deployer functionality
Reviewed Changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/algokit_utils/src/applications/app_factory/ | Core factory implementation with modular design (types, compilation, transaction builders, etc.) |
| crates/algokit_utils/src/applications/app_client/types.rs | Changed AlgorandClient parameter to Arc for shared ownership |
| crates/algokit_utils/src/clients/algorand_client.rs | Added persistent AppDeployer instance and app_deployer() accessor method |
| crates/algokit_utils/src/applications/app_deployer.rs | Enhanced with extra program pages calculation and localnet retry logic |
| crates/algokit_utils/tests/applications/app_factory.rs | Comprehensive test suite covering factory creation, deployment, and ABI scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
1be959c to
fb7ee7f
Compare
ae01c00 to
d9de8df
Compare
… in app client; more tests
* wip - PR feedback * wip - convert errors to snafu * wip * chore: replace utils CommonTransactionParams with macro * chore(python/algokit_transact): bump version to 1.0.0-alpha.60 [skip ci] * wip - converting string to error types * chore: simplify add_app_method_call_internal * chore: additional tweaks whilst implementing TS composer * chore(python/algokit_transact): bump version to 1.0.0-alpha.61 [skip ci] * chore: adjust transaction creator types, as they were previously a bit strange * wip - fixing compile issues * fix types for transaction_builder * chore: tweaks to both transaction creator and client manager * wip - map storage * wip - app state * wip - some clean up * wip - fix compile issues * make app state accessor better * wip - box * box done * fix params_builder * chore(python/algokit_transact): bump version to 1.0.0-alpha.62 [skip ci] * fix up the app client * wip - fix simulate * fix simulate + send params * clean up compilation.rs * remove extract_abi_return_from_result * wip - fixing tests * wip - resolve compile error app_client tests * wip - fixing tests * chore: add default signer support to AppClientParams * wip - structs * fix field type + encode/decode logic * test * convert storage key to abi storage key * convert storage map to abi storage map * convert box to use abi storage key * fix build * wip- struct in default value * convert default value * fix up - it builds now * wip - fixing tests --------- Co-authored-by: engineering-ci[bot] <179917785+engineering-ci[bot]@users.noreply.github.com> Co-authored-by: Neil Campbell <[email protected]> Co-authored-by: Altynbek Orumbayev <[email protected]>
afe47d6 to
092606d
Compare
…account for TransactionWithSigner Ensure transaction-typed ABI args inherit the method signer when not explicitly set
7d7e0f2 to
4c1741d
Compare
4c1741d to
94dc537
Compare
8f334f6 to
29cef4c
Compare
crates/algokit_utils/src/applications/app_client/params_builder.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/compilation.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/compilation.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/params_builder.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/transaction_sender.rs
Outdated
Show resolved
Hide resolved
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct AppFactoryMethodCallResult<T> { | ||
| inner: T, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For other part of the project, we are moving away from using nested structs, especially for public facing structs. For example, in this PR I removed the common_params from the send result. Do you think that we should do the same here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppFactoryMethodCallResult acts as a thin wrapper on top of SendAppResult type plus adds the parsed arc56 returns. The derefs below the lines you mentioned ensure that everything from SendAppResult is accessible from the root of the AppFactoryMethodCallResult - the user does not have to do extra hops to .inner in this case. So not sure we want to tweak it since all send result fields are immediately accessible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about the power of deref. However, This section from the Rust docs makes me wonder if this is suitable for public facing types.
When to implement Deref or DerefMut
The same advice applies to both deref traits. In general, deref traits should be implemented if:
a value of the type transparently behaves like a value of the target type;
the implementation of the deref function is cheap; and
users of the type will not be surprised by any deref coercion behavior.
In general, deref traits should not be implemented if:
the deref implementations could fail unexpectedly; or
the type has methods that are likely to collide with methods on the target type; or
committing to deref coercion as part of the public API is not desirable.
Especially this bit or committing to deref coercion as part of the public API is not desirable.
I am fairly new to Rust but deref seems to create a hidden API surface. For example, I didn't know about it until you pointed out to me that I could access everything inside inner because the AppFactoryMethodCallResult implement the deref trait.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considering that common params are removed in app client result types in https://github.com/algorandfoundation/algokit-core/pull/260/files - i considered using a macro for the app factory return types but ultimately the only change needed is extra arc56_return abivalue field - i ended up redeclaring fields instead of using deref or a macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this is the most pragmatic approach
crates/algokit_utils/src/applications/app_factory/transaction_sender.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/transaction_builder.rs
Outdated
Show resolved
Hide resolved
caad694 to
5e54f61
Compare
crates/algokit_utils/src/applications/app_factory/compilation.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/transaction_builder.rs
Outdated
Show resolved
Hide resolved
crates/algokit_utils/src/applications/app_factory/transaction_sender.rs
Outdated
Show resolved
Hide resolved
| fn signer_mut(&mut self) -> &mut Option<Arc<dyn TransactionSigner>>; | ||
| } | ||
|
|
||
| fn set_default_signer_if_missing( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: maybe a better name for this method is set_signer_if_missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to set_method_signer_if_missing which i think is slightly more explicit lmk if you are ok with this
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct AppFactoryMethodCallResult<T> { | ||
| inner: T, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about the power of deref. However, This section from the Rust docs makes me wonder if this is suitable for public facing types.
When to implement Deref or DerefMut
The same advice applies to both deref traits. In general, deref traits should be implemented if:
a value of the type transparently behaves like a value of the target type;
the implementation of the deref function is cheap; and
users of the type will not be surprised by any deref coercion behavior.
In general, deref traits should not be implemented if:
the deref implementations could fail unexpectedly; or
the type has methods that are likely to collide with methods on the target type; or
committing to deref coercion as part of the public API is not desirable.
Especially this bit or committing to deref coercion as part of the public API is not desirable.
I am fairly new to Rust but deref seems to create a hidden API surface. For example, I didn't know about it until you pointed out to me that I could access everything inside inner because the AppFactoryMethodCallResult implement the deref trait.
What do you think?
57792e3 to
41ef7a8
Compare
41ef7a8 to
f1fea56
Compare
|
🎉 This PR is included in version 1.0.0-alpha.68 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
App factory implementation following the AppClient