Draft
Conversation
345a0ba to
37d60d3
Compare
…ctionError - Add Strum dependencies for automatic Display/FromStr implementations - Replace manual Type::to_string() with Strum's Display derive - Create structured FunctionError and FunctionErrorRef enums - Replace string-based error formatting with type-safe errors - Use borrowing FunctionErrorRef to avoid unnecessary allocations
- Create Namespace enum with WellKnown and Custom variants - Add Strum traits for automatic string conversion - Replace all namespace: String with namespace: Namespace - Add From implementations for &Namespace borrowing - Convert namespace once before iteration to avoid multiple clones - Maintain backward compatibility with string conversions
- Replace &Vec<T> with &[T] for better API flexibility - Refactor arg_checker_with_ctx to use idiomatic patterns: - Early continue for optional inputs - Use ok_or_else with ? operator - Replace has_type_match flag with any() iterator method - Use pattern matching for type checking logic - Remove unnecessary type annotations and explicit returns
…module - Create TypeChecker struct with reusable type matching logic - Extract complex type compatibility rules from arg_checker_with_ctx - Add comprehensive tests for type compatibility scenarios - Simplify arg_checker_with_ctx to use TypeChecker::matches_any - Make type checking logic more maintainable and testable
- Replace manual Display implementation with Strum derive - Use serialize_all = "lowercase" to match previous output format - Reduce boilerplate code for DiagnosticLevel
Convert ActionItemRequest.internal_key from String to ActionItemKey enum for type safety and better pattern matching. Add serialization support to maintain JSON compatibility. Replace if/else chains with match expressions in signers.rs for cleaner code.
- Add ActionItemKey variants: Output, ProvideInput, CheckInput - Add SignerKey variant: IsBalanceChecked - Add Ord and PartialOrd derives to Namespace and WellKnownNamespace
- Replace string constants with ActionItemKey, DocumentationKey, NestedConstructKey, and RunbookKey enums - Fix function signatures from &Vec<T> to &[T] for trait compatibility - Add Namespace imports and conversions with .from() and .as_ref() - Remove redundant string constant declarations
- Convert &Namespace to &str using .as_ref() in persist_log calls
- Replace string constants with RunbookKey and DocumentationKey enums
- Fix function signatures from &Vec<Type> and &Vec<Value> to &[Type] and &[Value] - Add Namespace imports and conversions for arg_checker context
- Replace string constants with ActionItemKey and SignerKey enums - Fix function signatures from &Vec<Type> and &Vec<Value> to &[Type] and &[Value] - Add Namespace imports and conversions - Remove redundant string constant declarations
- Replace string constants with ActionItemKey and SignerKey enums - Add Namespace imports and conversions - Remove redundant string constant declarations
- Replace string constants with ActionItemKey and SignerKey enums - Fix function signatures from &Vec<Type> and &Vec<Value> to &[Type] and &[Value] - Add Namespace imports and conversions - Remove redundant string constant declarations
- Sync workspace dependency versions
Add Default impl and with_level helper to centralize initialization logic. Refactor error_from_string, warning_from_string, and note_from_string to use the helper instead of duplicating field initialization code.
Co-authored-by: Micaiah Reid <micaiahreid@gmail.com>
- Change ValueStore/ValueMap get methods to accept `impl AsRef<str>` - Change ValueStore/ValueMap insert methods to accept `impl ToString` - Remove hundreds of .as_ref() calls on enum keys for ValueStore operations - Keep .as_ref() for direct HashMap access (e.g., result.outputs.get()) - Add .to_string() for direct HashMap inserts (e.g., result.outputs.insert()) This allows using enum keys directly with ValueStore methods: values.get_string(DocumentationKey::Description) signer_state.insert_scoped_value(&key, SignerKey::TxHash, value)
Update main's new validation code to use type-safe constant enums: - Convert validation_helpers.rs to use DocumentationKey and ConditionKey enums - Fix ActionItemKey comparison in tests - Complete Default impl for Diagnostic - Use NestedConstructKey enum in deploy_program.rs - Remove duplicate strum dependency entry
37d60d3 to
592577d
Compare
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.
Purpose
This document catalogs refactoring patterns explored in the
feat/addon-kit-factorbranch. It's intended as a discussion guide for maintainers to review each change category and decide which improvements are worth integrating into the main codebase.The PR has been factored into 9 smaller efforts that stack on each other (1-9), allowing for easier review, and discrete choices.
1. Structured Function Errors (akf-01)
Before (ad-hoc error string formatting)
After (structured error types with Display)
Benefits:
FunctionErrorRefavoids allocations in performance-critical code2. Namespace Type Safety (akf-02)
Before
After
Benefits:
3. Idiomatic Function API Signatures (akf-03)
Before
After
Benefits:
&[T]is more flexible (accepts arrays, vectors, slices) and follows Rust API guidelines.4. Type Compatibility Logic Extraction (akf-04)
Before (inline complex matching in arg_checker)
After (dedicated TypeChecker with unit tests)
Benefits:
5. DRY Violation in Diagnostic Constructors (akf-05)
Before (51 lines of duplicated code)
After (23 lines, centralized logic)
Impact: -51 lines, +23 lines. Single point of maintenance for default field initialization.
6. Type-Safe Constant Enums (akf-06)
Before (scattered string constants)
After (organized, type-safe enums)
Benefits:
Display,FromStr,AsRef<str>derived automatically7. Core Migrations (akf-07)
Migrate
txtx-core,txtx-cli,txtx-cloud,txtx-gqlto use the type-safe constant enums introduced in akf-06.Before
After
Benefits:
FromStrfor validation8. Addon Migrations (akf-08)
Migrate bitcoin, evm, stacks, and svm addons to use type-safe constant enums.
Before
After
Benefits:
9. ValueStore API Ergonomics (akf-09)
Before (verbose
.as_ref()everywhere)After (clean enum usage)
Impact: Removed hundreds of
.as_ref()calls across 30 files while maintaining type safety.Metrics Summary
.as_ref()calls&Vec<T>&[T]