Commit ddb186a
[sdk] Add support for public struct/enum transaction arguments
Implement complete support for passing public copy structs and enums
as transaction arguments in JSON format, mirroring functionality in
the Rust CLI (aptos-core#18591).
Features:
- Automatic type inference from function ABI
- Nested structs/enums support (up to 7 levels deep)
- Generic type parameter substitution (T0, T1, etc.)
- Support for all Move primitive types (bool, u8-u256, i8-i256, address)
- Special framework types (String, Object<T>, Option<T>)
- Option<T> dual format support (vector and enum formats)
- Module ABI caching for performance
- Comprehensive validation and error messages
Implementation:
- MoveStructArgument and MoveEnumArgument BCS-serializable classes
- StructEnumArgumentParser with full encoding logic:
* Fetches module ABI from REST API for struct/enum definitions
* Encodes struct fields in declaration order
* Encodes enum variants with ULEB128 indices
* Recursive encoding for nested types
* Generic type parameter substitution with bounds checking
- Integration into transaction builder:
* Made argument conversion functions async (convertArgument, parseArg)
* Added struct/enum detection logic in parseArg
* Updated transaction builder to handle async conversions
- Complete type support:
* All primitives (bool, u8-u256, i8-i256, address)
* Vectors with recursive element encoding
* Special framework types (String, Object<T>, Option<T>)
Testing:
- 70+ comprehensive unit tests with mocked module ABIs
- Tests cover: struct/enum encoding, generics, nested types, depth limits,
error cases, Option formats, framework types, caching
Documentation:
- JSDoc with 5 usage examples in StructEnumArgumentParser class
- README section with 6 practical examples
- CHANGELOG entry with breaking changes and feature list
- Complete design document (STRUCT_ENUM_SUPPORT.md)
Breaking Changes:
- Argument conversion functions are now async to support fetching module ABIs
- Impact is minimal since top-level APIs like generateTransactionPayload
were already async
Files:
- src/transactions/transactionBuilder/structEnumParser.ts: Complete parser implementation
- src/transactions/transactionBuilder/remoteAbi.ts: Async conversion with struct/enum support
- src/transactions/transactionBuilder/transactionBuilder.ts: Async transaction building
- src/transactions/types.ts: Added MoveStructArgument and MoveEnumArgument to type system
- src/internal/digitalAsset.ts: Async property value encoding
- tests/unit/structEnumParser.test.ts: Comprehensive test suite (70+ tests)
- tests/e2e/transaction/transactionArguments.test.ts: Updated for async
- tests/unit/remoteAbi.test.ts: Updated for async
- README.md: Usage examples section
- CHANGELOG.md: Breaking changes and features
- STRUCT_ENUM_SUPPORT.md: Complete design and status document
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent d10017e commit ddb186a
File tree
13 files changed
+2681
-497
lines changed- src
- internal
- transactions
- transactionBuilder
- tests
- e2e/transaction
- unit
13 files changed
+2681
-497
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
13 | 26 | | |
14 | 27 | | |
15 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
225 | 311 | | |
226 | 312 | | |
227 | 313 | | |
| |||
0 commit comments