feat(tii): type-directed argument encoding to the TaggedArg wire form#43
Merged
Conversation
Marshal every arg through one recursive walk over `(ParamType, value)` in `tii::encode`, wired into `Invocation::into_resolve_request`. A scalar leaf renders bare at the top level (the resolver coerces it via the flat TIR type) and tagged when nested in an aggregate; aggregates (list/tuple/map/record/variant) render to the self-describing tagged form. There is no separate scalar/aggregate path — scalars are the leaf cases of the same walk. Records map the user's by-name object to positional `struct` fields in declared order, taken from the schema's `required` array (which `tx3c` emits in source order — `properties` is alphabetized and must not drive field order). Variants resolve the case index from the `oneOf` ordering. Map keys are carried as `string` leaves (the `.tii` erases the key type), pairs sorted by key. Ill-shaped values (missing/extra field, wrong arity, unknown case) are rejected before sending. BREAKING: `ParamType::Record` now carries ordered `Vec<(String, ParamType)>` instead of a `BTreeMap`, with a `ParamType::field(name)` accessor for by-name lookup. Tests drive the shared cross-SDK oracle (accept + reject vectors) plus an end-to-end `into_resolve_request` check on a real TII. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
What
Teaches the SDK to serialize an argument of an aggregate type (record,
List,Map,Tuple, variant) into the TRPTaggedArgwire form, sotrix invoke/ any SDK consumer can pass complex args. Newtii::encode, wired intoInvocation::into_resolve_request.One walk, not two paths
encode(param, value)is a single recursive walk over(type, value)— scalars are just the leaf cases:So every mapped arg goes through
encode; there's nois_aggregategate. Bare top-level scalars keep the exact pre-existing wire shape, so this is back-compatible for scalar-only protocols.Encoding rules
{ "struct": { "constructor": 0, "fields": [<declared order>] } }. Field order comes from the schema'srequiredarray —tx3cemits it in source-declaration order, whereaspropertiesis alphabetized, sorequired(notproperties) drives positional order.structwithconstructor= the case index in the.tiioneOfordering.[key, value]pairs; keys arestringleaves (the.tiierases the Tx3 key type), pairs sorted by key for determinism.unknown/utxo/anyAssetparams pass through unchanged (no element types to drive encoding).Breaking change
ParamType::Recordnow carries an orderedVec<(String, ParamType)>instead of aBTreeMap(the encoder needs declared order). AddedParamType::field(name)for by-name lookup. This is the coordinated breaking SDK change; the version bump + publish are a separate release step.Tests
tests/fixtures/wire-vectors.json, mirrored fromsdk-spec): everyacceptvector encodes byte-equal, everyrejectvector errors.Meta { tags, level }→[list, int], not alphabetical[int, list]).into_resolve_requeston a real TII:metatagged, scalars bare.cargo test -p tx3-sdk --libgreen (23);cargo clippy --libclean.🤖 Generated with Claude Code