Skip to content

Support typed JSON values in transaction metadata#5587

Merged
takemiyamakoto merged 1 commit into
optimizationsfrom
bugfix/typed-json-metadata
Jun 9, 2026
Merged

Support typed JSON values in transaction metadata#5587
takemiyamakoto merged 1 commit into
optimizationsfrom
bugfix/typed-json-metadata

Conversation

@SDILogin

Copy link
Copy Markdown
Contributor

Summary

TransactionPayload.metadata was Map<String, String>. The MetadataEntryAdapter always wrapped every value through encodeJsonString(), producing JSON strings on the wire. Iroha's executor rejects transactions whose gas_limit is a JSON string ("1000") — it requires a JSON number (1000).

Changes

  • New JsonValue inline value class (core/model/JsonValue.kt) — wraps a raw JSON literal with factory methods: string() (quotes + escapes), number() (bare digits), bool(), raw()
  • TransactionPayload.metadata type changed from Map<String, String> to Map<String, JsonValue>
  • TransactionPayloadAdapter — replaced JsonAdapter/JsonStringAdapter with JsonValueFieldAdapter that writes rawJson directly through STRING_ADAPTER. Removed encodeJsonString, decodeJsonString, parseJsonString, hexNibble, HEX_DIGITS (all now unused)
  • Tests updated to use JsonValue.string() / JsonValue.number() where metadata is constructed

Wire format

String values produce identical bytesJsonValue.string("hello").rawJson is "hello" (with quotes), same as the old encodeJsonString("hello"). Number values like JsonValue.number(1000) emit 1000 (4 bytes, no quotes) instead of the old "1000" (6 bytes with quotes).

Usage

val payload = TransactionPayload(
    // ...
    metadata = mapOf(
        "gas_asset_id" to JsonValue.string(gasAssetId),
        "gas_limit"    to JsonValue.number(1000),
    ),
)

Replace Map<String, String> with Map<String, JsonValue> so metadata
can carry JSON numbers and booleans alongside strings. Iroha rejects
gas_limit encoded as a JSON string; the new JsonValue.number() emits
a raw JSON number on the wire.

Signed-off-by: Dmitry Selivanov <diselivanov@gmail.com>
@SDILogin SDILogin force-pushed the bugfix/typed-json-metadata branch from 3237047 to 25635c1 Compare June 9, 2026 10:29
@takemiyamakoto takemiyamakoto merged commit f383456 into optimizations Jun 9, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In review to Testing & Verification in Iroha Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants