Files
zeekay 9098761124 The numerics state the shape they marshal into
Each of these writes itself as a quoted decimal — a JSON number is a float64, so
a uint64 above 2^53 does not survive one — which means a schema built from the
Go fields would describe the integer and not the wire. zip published `{}` for
every one of them: true, since the fields are not the wire form, and useless to
anything generating a client, which then types the field as an untyped value.

The shape is declared beside MarshalJSON because the bytes and the schema are
the same fact about the same type. zip reads it through SchemaDescriber.

This is the JSON EDGE only. On the ZAP plane a u64 is a u64 and none of this
applies — the quoting exists because browsers speak JSON, and it stops at the
boundary where they do.
2026-08-29 13:38:46 -07:00

38 lines
1.5 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package types
// Each numeric here writes itself as a quoted decimal, so a schema built from
// its fields would describe the Go integer and not the wire. Stating the shape
// beside MarshalJSON is what keeps the two from disagreeing, and it is what
// lets a generated client type the field instead of receiving an untyped
// value. zip reads these through its SchemaDescriber interface.
//
// The pattern is the constraint that matters: the value is digits in a string,
// which is the whole reason these types exist — a JSON number is a float64,
// and a uint64 above 2^53 does not survive one.
func quotedInteger(bits string) map[string]any {
return map[string]any{
"type": "string",
"pattern": "^[0-9]+$",
"description": "An unsigned " + bits + "-bit integer, carried as a decimal string.",
}
}
func (Uint16) JSONSchema() map[string]any { return quotedInteger("16") }
func (Uint32) JSONSchema() map[string]any { return quotedInteger("32") }
func (Uint64) JSONSchema() map[string]any { return quotedInteger("64") }
// Uint256 is the width the EVM carries; it does not fit any JSON numeric.
func (Uint256) JSONSchema() map[string]any { return quotedInteger("256") }
func (Float64) JSONSchema() map[string]any {
return map[string]any{
"type": "string",
"pattern": "^-?[0-9]+\\.[0-9]+$",
"description": "A 64-bit float, carried as a decimal string.",
}
}