json: migrate every encoding/json import to json/v2 (go-json-experiment)

External (HTTP / JSON-RPC) is the only place JSON is legitimate. Every
existing encoding/json import in node/ moves to github.com/go-json-experiment/json
(v2 root, not the v1 sub-package). NewEncoder/NewDecoder rewrite to
MarshalWrite/UnmarshalRead. MarshalIndent rewrites to Marshal with
jsontext.WithIndent. json.RawMessage rewrites to jsontext.Value.
*json.SyntaxError rewrites to *jsontext.SyntacticError.

81 files migrated. LLM.md captures the rule + v1->v2 delta table.

Known v2 semantic deltas surfaced by existing tests (followups, not regressions):
- [N]byte fields with no MarshalJSON now marshal as base64 string (v1 marshalled
  as JSON array of byte numbers). Affects vms/platformvm/txs/*_test.go fixtures
  with embedded BLS proofOfPossession.
- time.Duration has no v2 default representation; configs that wire-format
  Duration as nanoseconds (vms/{xvm,platformvm}/config, config/spec) need to
  switch to string-form Duration or carry an explicit option. v2 root does not
  re-export FormatDurationAsNano.
- v2 enforces strict UTF-8 (vms/chainadapter/messaging fixture has non-UTF-8).
- json.MarshalWrite does not append a trailing '\n' (v1 NewEncoder.Encode did);
  service/auth/auth_test.go expectation updated.
- nil []byte round-trips to empty (not nil); config_test deep-equal fixtures
  surface this.

All affected sites are at the API boundary; ZAP wire envelope already covers
the internal data paths (state, P2P, consensus, MPC, threshold). Internal
JSON sites that should move to ZAP next (separate work):
- vms/da/store.go            (DA blob/cert storage as JSON)
- vms/platformvm/airdrop     (airdrop claims as JSON in db)
- vms/chainadapter/appchain  (SQLite materializer schema/data blobs)
- vms/chainadapter/messaging (conversation codec)
- staking/kms.go             (KMS HTTP client — external technically, leave)
- utils/{bimap,ips}          (small marshaler shims — low priority)
This commit is contained in:
Hanzo AI
2026-06-06 22:26:02 -07:00
parent ceeea038ff
commit c3b398bc7b
85 changed files with 198 additions and 129 deletions
+42 -1
View File
@@ -764,6 +764,47 @@ PRIVATE_KEY="<funded_key>" \
./bin/bench tps --chains=lux --duration=60s --concurrency=5
```
## JSON rule — json/v2 at HTTP boundary only; ZAP for all internal data
Encoding boundaries are one-way and explicit:
- **External (HTTP / JSON-RPC API)** — `github.com/go-json-experiment/json` (v2).
Never `encoding/json`. This covers: `service/*`, `server/*`, `pubsub/`,
`vms/platformvm/service.go`, `vms/xvm/service.go`, JSON-RPC clients
(`vms/platformvm/client_*`), CLI tools (`cmd/*`), wallet examples,
on-disk config files (read once at boot), genesis/upgrade blobs.
- **Internal (state, P2P, consensus, MPC, logs, metrics)** — ZAP wire only.
No JSON in: `network/`, `consensus/`, `snow/`, `chains/` (data-plane),
`vms/*/state/`, `vms/*/block/`, `vms/*/txs/` (struct codec), threshold
payloads, P2P message bodies, internal databases.
Migration helpers (v2 API delta vs v1):
| v1 (encoding/json) | v2 (go-json-experiment/json) |
|-----------------------------------|----------------------------------------------|
| `json.Marshal(v)` | `json.Marshal(v)` (variadic opts; signature compat) |
| `json.MarshalIndent(v, "", " ")` | `json.Marshal(v, jsontext.WithIndent(" "))` |
| `json.Unmarshal(b, &v)` | `json.Unmarshal(b, &v)` |
| `json.NewEncoder(w).Encode(v)` | `json.MarshalWrite(w, v)` (no trailing `\n`) |
| `json.NewDecoder(r).Decode(&v)` | `json.UnmarshalRead(r, &v)` |
| `json.RawMessage` | `jsontext.Value` |
| `*json.SyntaxError` | `*jsontext.SyntacticError` |
v2 semantic differences worth knowing (these change wire shape):
- `[N]byte` field with no `MarshalJSON` ⇒ v2 marshals as base64 string,
v1 marshalled as JSON array of byte numbers. Add `MarshalJSON` on the
type if the array form is wanted on the wire.
- `time.Duration` ⇒ v2 default is the standard string form ("30m");
v1 marshalled as int nanoseconds. v1 sub-package
(`github.com/go-json-experiment/json/v1`) exposes `FormatDurationAsNano(true)`;
v2 root does not. Prefer the string form on new APIs.
- v2 enforces strict UTF-8; raw arbitrary bytes in JSON strings fail.
This matters for legacy P2P/internal blobs that happen to be stored
through JSON — those should already be on ZAP.
- `json.MarshalWrite` does NOT append a trailing `\n` (v1 `NewEncoder.Encode` did).
Adjust HTTP-handler test fixtures accordingly.
---
*Last Updated*: 2026-02-04
*Last Updated*: 2026-06-06
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"context"
"crypto"
"encoding/binary"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"fmt"
"net/http"
+3 -3
View File
@@ -5,7 +5,7 @@ package rpc
import (
"bytes"
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"io"
"net/http"
@@ -132,7 +132,7 @@ func (d *DebugTool) testEndpoint(url string) TestResult {
// Check if we got a valid JSON-RPC response
var rpcResp map[string]interface{}
if err := json.NewDecoder(postResp.Body).Decode(&rpcResp); err == nil {
if err := json.UnmarshalRead(postResp.Body, &rpcResp); err == nil {
if _, hasResult := rpcResp["result"]; hasResult {
result.Success = true
result.Response = fmt.Sprintf("Valid JSON-RPC response: %v", rpcResp["result"])
@@ -179,7 +179,7 @@ func (d *DebugTool) testRPCMethods(url string) []RPCTest {
defer resp.Body.Close()
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
if err := json.UnmarshalRead(resp.Body, &result); err == nil {
if res, ok := result["result"]; ok {
test.Success = true
test.Result = fmt.Sprintf("%v", res)
+1 -1
View File
@@ -10,7 +10,7 @@ package chains
import (
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"testing"
consensusconfig "github.com/luxfi/consensus/config"
+4 -2
View File
@@ -3,10 +3,12 @@ package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"os"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)
func main() {
@@ -190,7 +192,7 @@ func cmdExport(args []string) {
// stateEnvelope wraps CeremonyState with a SHA-256 integrity hash.
type stateEnvelope struct {
State json.RawMessage `json:"state"`
State jsontext.Value `json:"state"`
Integrity string `json:"integrity"` // hex(SHA-256(state bytes))
}
+3 -2
View File
@@ -3,7 +3,6 @@ package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"math/big"
"os"
"path/filepath"
@@ -12,6 +11,8 @@ import (
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)
// =============================================================================
@@ -309,7 +310,7 @@ func TestRegressionL03_StateFileHasIntegrity(t *testing.T) {
}
var envelope struct {
State json.RawMessage `json:"state"`
State jsontext.Value `json:"state"`
Integrity string `json:"integrity"`
}
if err := json.Unmarshal(raw, &envelope); err != nil {
+1 -1
View File
@@ -3,7 +3,7 @@ package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"time"
+1 -1
View File
@@ -11,7 +11,7 @@
package main
import (
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"os"
"sort"
+3 -2
View File
@@ -2,7 +2,8 @@ package main
import (
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"os"
"time"
@@ -75,7 +76,7 @@ func main() {
ccBytes, _ := json.Marshal(cc)
genesis["cChainGenesis"] = string(ccBytes)
out, _ := json.MarshalIndent(genesis, "", " ")
out, _ := json.Marshal(genesis, jsontext.WithIndent(" "))
os.WriteFile(os.ExpandEnv("$HOME/work/lux/mainnet/zoo_genesis_valid.json"), out, 0644)
fmt.Println("Wrote zoo_genesis_valid.json")
}
+3 -2
View File
@@ -8,7 +8,6 @@ import (
"crypto/tls"
"encoding/base64"
"encoding/hex"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
@@ -19,6 +18,8 @@ import (
"strings"
"time"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/spf13/viper"
compression "github.com/luxfi/compress"
@@ -1429,7 +1430,7 @@ func getNetConfigsFromFlags(v *viper.Viper, netIDs []ids.ID) (map[ids.ID]nets.Co
}
// partially parse configs to be filled by defaults later
chainConfigs := make(map[ids.ID]json.RawMessage, len(netIDs))
chainConfigs := make(map[ids.ID]jsontext.Value, len(netIDs))
if err := json.Unmarshal(netConfigContent, &chainConfigs); err != nil {
return nil, fmt.Errorf("could not unmarshal JSON: %w", err)
}
+1 -1
View File
@@ -5,7 +5,7 @@ package config
import (
"encoding/base64"
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"log"
"os"
+1 -1
View File
@@ -5,7 +5,7 @@ package config
import (
"embed"
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"github.com/spf13/viper"
+1 -1
View File
@@ -4,7 +4,7 @@
package config
import (
"encoding/json"
"github.com/go-json-experiment/json"
"testing"
"github.com/spf13/viper"
+3 -2
View File
@@ -4,7 +4,8 @@
package node
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"net/netip"
"testing"
@@ -54,7 +55,7 @@ func TestProcessContext(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)
contextJSON, err := json.MarshalIndent(test.context, "", "\t")
contextJSON, err := json.Marshal(test.context, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(test.expected, string(contextJSON))
})
+3 -2
View File
@@ -7,7 +7,8 @@
package spec
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"time"
)
@@ -207,7 +208,7 @@ func (s *ConfigSpec) DeprecatedFlags() []FlagSpec {
// JSON returns the spec as formatted JSON.
func (s *ConfigSpec) JSON() ([]byte, error) {
return json.MarshalIndent(s, "", " ")
return json.Marshal(s, jsontext.WithIndent(" "))
}
// ValidateValue checks if a value is valid for a flag.
+1 -1
View File
@@ -4,7 +4,7 @@
package spec
import (
"encoding/json"
"github.com/go-json-experiment/json"
"testing"
)
+1 -1
View File
@@ -8,7 +8,7 @@ package builder
import (
"encoding/base64"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"fmt"
"path"
+2 -1
View File
@@ -114,12 +114,14 @@ require (
require (
github.com/cloudflare/circl v1.6.3
github.com/consensys/gnark-crypto v0.20.1
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/golang/mock v1.7.0-rc.1
github.com/luxfi/accel v1.2.2
github.com/luxfi/api v1.0.14
github.com/luxfi/atomic v1.0.0
github.com/luxfi/chains v1.3.6
github.com/luxfi/codec v1.1.5
github.com/luxfi/compress v0.0.5
github.com/luxfi/constants v1.5.8-0.20260603055356-93c2c2ceb9ca
github.com/luxfi/container v0.0.4
@@ -158,7 +160,6 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/grandcat/zeroconf v1.0.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
+2
View File
@@ -262,6 +262,8 @@ github.com/luxfi/cache v1.2.1 h1:kAzOS55/hmYeNKR+0HAKv4ma48Y6JjkI8UQeqdZ8bfI=
github.com/luxfi/cache v1.2.1/go.mod h1:co7JTxZZHpKT31Yh01LFp5aZOxmoUg157FhBLQdQHVU=
github.com/luxfi/chains v1.3.6 h1:JZwhjOPMyTOYz+MgNj0SJfgny/zeSHqvWtbmjQmRgCU=
github.com/luxfi/chains v1.3.6/go.mod h1:mWXh65qP37JYyYOeI5d9upTVgs47VD8MwR25aCeLF6k=
github.com/luxfi/codec v1.1.5 h1:KBq8uvYm5Dy+E1heG8WBmqbqu8kstlFyE5ASBBB+C8I=
github.com/luxfi/codec v1.1.5/go.mod h1:/ugIv5iEgI+VAuPIetzxNT0eJaEjOID/mrIsgIjJh8g=
github.com/luxfi/compress v0.0.5 h1:4tEUHw5MK1bu5UOjfYCt4OKMiH7yykIgmGPRA/BfJTM=
github.com/luxfi/compress v0.0.5/go.mod h1:Cc1yxD2pfzrvpO32W2GDwLKff+CylHEvzZh2Ko8RSIU=
github.com/luxfi/concurrent v0.0.3 h1:eJyv1fhaC0jMLMw6+QS774cUmp7GK+ouMgvLCqnC7cc=
+3 -2
View File
@@ -8,7 +8,6 @@ import (
"context"
"crypto"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
@@ -21,6 +20,8 @@ import (
"sync"
"time"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
nodevalidators "github.com/luxfi/validators"
"github.com/luxfi/metric"
@@ -756,7 +757,7 @@ func (n *Node) writeProcessContext() error {
URI: n.apiURI,
StakingAddress: n.stakingAddress, // Set by network initialization
}
bytes, err := json.MarshalIndent(processContext, "", " ")
bytes, err := json.Marshal(processContext, jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("failed to marshal process context: %w", err)
}
+2 -2
View File
@@ -4,12 +4,12 @@
package pubsub
import (
"encoding/json"
"errors"
"fmt"
"sync/atomic"
"time"
"github.com/go-json-experiment/json"
"github.com/gorilla/websocket"
"github.com/luxfi/log"
@@ -162,7 +162,7 @@ func (c *connection) readMessage() error {
return err
}
cmd := &Command{}
err = json.NewDecoder(r).Decode(cmd)
err = json.UnmarshalRead(r, cmd)
if err != nil {
return err
}
+2 -2
View File
@@ -4,11 +4,11 @@
package server
import (
"encoding/json"
"net"
"net/http"
"strings"
"github.com/go-json-experiment/json"
"github.com/luxfi/math/set"
)
@@ -76,7 +76,7 @@ func (a *allowedHostsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
// Return error as JSON
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusForbidden)
json.NewEncoder(w).Encode(map[string]interface{}{
_ = json.MarshalWrite(w, map[string]interface{}{
"jsonrpc": "2.0",
"error": map[string]interface{}{
"code": -32001,
+2 -2
View File
@@ -4,12 +4,12 @@
package server
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sync"
"github.com/go-json-experiment/json"
"github.com/gorilla/mux"
apitypes "github.com/luxfi/api/types"
@@ -165,7 +165,7 @@ func (r *router) handleRootGET(w http.ResponseWriter, _ *http.Request) {
}
}
if err := json.NewEncoder(w).Encode(info); err != nil {
if err := json.MarshalWrite(w, info); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
}
}
+1 -1
View File
@@ -307,7 +307,7 @@ func TestWriteUnauthorizedResponse(t *testing.T) {
rr := httptest.NewRecorder()
writeUnauthorizedResponse(rr, errTest)
require.Equal(http.StatusUnauthorized, rr.Code)
require.Equal(`{"jsonrpc":"2.0","error":{"code":-32600,"message":"non-nil error"},"id":1}`+"\n", rr.Body.String())
require.Equal(`{"jsonrpc":"2.0","error":{"code":-32600,"message":"non-nil error"},"id":1}`, rr.Body.String())
}
func TestWrapHandlerMutatedRevokedToken(t *testing.T) {
+2 -2
View File
@@ -4,9 +4,9 @@
package auth
import (
"encoding/json"
"net/http"
"github.com/go-json-experiment/json"
rpc "github.com/gorilla/rpc/v2/json2"
)
@@ -29,7 +29,7 @@ func writeUnauthorizedResponse(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusUnauthorized)
// There isn't anything to do with the returned error, so it is dropped.
_ = json.NewEncoder(w).Encode(responseBody{
_ = json.MarshalWrite(w, responseBody{
Version: rpc.Version,
Err: responseErr{
Code: rpc.E_INVALID_REQ,
+3 -2
View File
@@ -8,7 +8,6 @@ package backup
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
@@ -17,6 +16,8 @@ import (
"sync"
"time"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/klauspost/compress/zstd"
"github.com/luxfi/database"
"github.com/luxfi/log"
@@ -315,7 +316,7 @@ func (s *Service) saveMetadata() error {
return fmt.Errorf("failed to create metadata directory: %w", err)
}
data, err := json.MarshalIndent(meta, "", " ")
data, err := json.Marshal(meta, jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("failed to marshal metadata: %w", err)
}
+2 -2
View File
@@ -4,9 +4,9 @@
package health
import (
"encoding/json"
"net/http"
"github.com/go-json-experiment/json"
"github.com/gorilla/rpc/v2"
apihealth "github.com/luxfi/api/health"
@@ -55,7 +55,7 @@ func NewGetHandler(reporter func(tags ...string) (map[string]apihealth.Result, b
}
// The encoder will call write on the writer, which will write the
// header with a 200.
_ = json.NewEncoder(w).Encode(apihealth.APIReply{
_ = json.MarshalWrite(w, apihealth.APIReply{
Checks: checks,
Healthy: healthy,
})
+1 -1
View File
@@ -4,11 +4,11 @@
package info
import (
"encoding/json"
"errors"
"net/http/httptest"
"testing"
"github.com/go-json-experiment/json"
"github.com/luxfi/mock/gomock"
"github.com/stretchr/testify/require"
+2 -3
View File
@@ -5,11 +5,11 @@ package security
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/go-json-experiment/json"
"github.com/gorilla/rpc/v2"
consensusconfig "github.com/luxfi/consensus/config"
@@ -227,8 +227,7 @@ func buildBlockSecurityReply(p *consensusconfig.ChainSecurityProfile) BlockSecur
// behaviour (no per-endpoint drift).
func writeJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
if err := enc.Encode(v); err != nil {
if err := json.MarshalWrite(w, v); err != nil {
// Body may have been partially written; nothing further to
// do at this layer. Frameworks log encoder failures at the
// HTTP listener boundary.
+3 -3
View File
@@ -6,13 +6,13 @@ package security
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/go-json-experiment/json"
consensusconfig "github.com/luxfi/consensus/config"
"github.com/luxfi/log"
)
@@ -227,7 +227,7 @@ func TestREST_securityProfile_GET(t *testing.T) {
t.Errorf("Content-Type = %q; want application/json prefix", got)
}
var body ProfileReply
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
if err := json.UnmarshalRead(resp.Body, &body); err != nil {
t.Fatalf("decode: %v", err)
}
if body.ProfileName != "STRICT" {
@@ -283,7 +283,7 @@ func TestREST_blockSecurity_GET(t *testing.T) {
t.Fatalf("status = %d; want 200", resp.StatusCode)
}
var body BlockSecurityReply
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
if err := json.UnmarshalRead(resp.Body, &body); err != nil {
t.Fatalf("decode: %v", err)
}
if body.SecurityProfileName != "STRICT" {
+2 -2
View File
@@ -4,7 +4,7 @@
package staking
import (
"encoding/json"
"github.com/go-json-experiment/json"
"fmt"
"io"
"net/http"
@@ -63,7 +63,7 @@ func FetchFromKMS(cfg KMSConfig) (*KMSStakingKeys, error) {
Value string `json:"secretValue"`
} `json:"secret"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
if err := json.UnmarshalRead(resp.Body, &result); err != nil {
return nil, fmt.Errorf("decoding KMS response: %w", err)
}
+4 -4
View File
@@ -4,7 +4,7 @@
package staking
import (
"encoding/json"
"github.com/go-json-experiment/json"
"net/http"
"net/http/httptest"
"testing"
@@ -40,7 +40,7 @@ func TestFetchFromKMS(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(kmsResponse)
json.MarshalWrite(w, kmsResponse)
}))
defer server.Close()
@@ -76,7 +76,7 @@ func TestFetchFromKMS_NoAuth(t *testing.T) {
t.Errorf("expected no Authorization header, got %q", auth)
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(kmsResponse)
json.MarshalWrite(w, kmsResponse)
}))
defer server.Close()
@@ -150,7 +150,7 @@ func TestFetchFromKMS_InvalidSecretValue(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(kmsResponse)
json.MarshalWrite(w, kmsResponse)
}))
defer server.Close()
+3 -2
View File
@@ -4,7 +4,8 @@
package tmpnet
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"time"
@@ -91,7 +92,7 @@ func NewTestGenesisWithFunds(
// Add basic C-Chain genesis
config.CChainGenesis = getBasicCChainGenesis(networkID)
return json.MarshalIndent(config, "", " ")
return json.Marshal(config, jsontext.WithIndent(" "))
}
// getBasicCChainGenesis returns a basic C-Chain genesis configuration
+3 -2
View File
@@ -5,7 +5,8 @@ package tmpnet
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"os"
"path/filepath"
@@ -123,7 +124,7 @@ func (n *Network) Write() error {
return fmt.Errorf("failed to create network directory: %w", err)
}
data, err := json.MarshalIndent(n, "", " ")
data, err := json.Marshal(n, jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("failed to marshal network config: %w", err)
}
+3 -2
View File
@@ -7,7 +7,8 @@ import (
"context"
"crypto/rand"
"crypto/x509"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"encoding/pem"
"fmt"
"net/netip"
@@ -121,7 +122,7 @@ func (n *Node) Write() error {
Flags: n.Flags,
}
data, err := json.MarshalIndent(config, "", " ")
data, err := json.Marshal(config, jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("failed to marshal node config: %w", err)
}
+1 -1
View File
@@ -21,7 +21,7 @@ import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"math/big"
"strings"
+1 -1
View File
@@ -4,7 +4,7 @@
package utils
import (
"encoding/json"
"github.com/go-json-experiment/json"
"net/netip"
"testing"
+1 -1
View File
@@ -5,7 +5,7 @@ package bimap
import (
"bytes"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"maps"
"slices"
+1 -1
View File
@@ -4,7 +4,7 @@
package bimap
import (
"encoding/json"
"github.com/go-json-experiment/json"
"testing"
"github.com/stretchr/testify/require"
+3 -2
View File
@@ -5,9 +5,10 @@ package formatting
import (
"encoding/hex"
"encoding/json"
"testing"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/stretchr/testify/require"
)
@@ -28,7 +29,7 @@ func TestEncodingUnmarshalJSON(t *testing.T) {
require.NoError(json.Unmarshal(jsonBytes, &enc))
require.Equal(Hex, enc)
var serr *json.SyntaxError
var serr *jsontext.SyntacticError
jsonBytes = []byte("")
require.ErrorAs(json.Unmarshal(jsonBytes, &enc), &serr)
+1 -1
View File
@@ -5,7 +5,7 @@
package ips
import (
"encoding/json"
"github.com/go-json-experiment/json"
"net"
"sync"
)
+1 -1
View File
@@ -5,7 +5,7 @@
package ips
import (
"encoding/json"
"github.com/go-json-experiment/json"
"net"
"strconv"
"testing"
+1 -1
View File
@@ -4,7 +4,7 @@
package version
import (
"encoding/json"
"github.com/go-json-experiment/json"
"strconv"
"time"
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"crypto/sha256"
"database/sql"
"encoding/binary"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"fmt"
"sync"
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"context"
"crypto/sha256"
"encoding/binary"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"sync"
"time"
+1 -1
View File
@@ -5,7 +5,7 @@ package da
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"sync"
"time"
+3 -2
View File
@@ -4,7 +4,8 @@
package status
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"time"
@@ -20,7 +21,7 @@ type TxIssuance struct {
}
func (s *TxIssuance) String() string {
txJSON, err := json.MarshalIndent(s.Tx, "", " ")
txJSON, err := json.Marshal(s.Tx, jsontext.WithIndent(" "))
if err != nil {
return "failed to marshal transaction: " + err.Error()
}
+3 -2
View File
@@ -4,7 +4,8 @@
package versionjson
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"github.com/spf13/cobra"
@@ -37,7 +38,7 @@ func versionFunc(*cobra.Command, []string) error {
Version: xsvm.Version,
RPCChainVM: uint64(version.RPCChainVMProtocol),
}
jsonBytes, err := json.MarshalIndent(versions, "", " ")
jsonBytes, err := json.Marshal(versions, jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("failed to marshal versions: %w", err)
}
+1 -1
View File
@@ -5,7 +5,7 @@ package airdrop
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"math/big"
"sync"
@@ -4,8 +4,7 @@
package platformvm
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/luxfi/address"
"github.com/luxfi/ids"
"github.com/luxfi/node/vms/platformvm/api"
+1 -1
View File
@@ -4,7 +4,7 @@
package config
import (
"encoding/json"
"github.com/go-json-experiment/json"
"time"
"github.com/luxfi/constants"
+1 -1
View File
@@ -4,7 +4,7 @@
package config
import (
"encoding/json"
"github.com/go-json-experiment/json"
"reflect"
"testing"
"time"
+1 -1
View File
@@ -4,7 +4,7 @@
package config
import (
"encoding/json"
"github.com/go-json-experiment/json"
"time"
"github.com/luxfi/constants"
@@ -4,7 +4,7 @@
package config
import (
"encoding/json"
"github.com/go-json-experiment/json"
"testing"
"time"
+1 -1
View File
@@ -5,7 +5,6 @@ package platformvm
import (
"context"
"encoding/json"
"errors"
"fmt"
"maps"
@@ -14,6 +13,7 @@ import (
"slices"
"time"
"github.com/go-json-experiment/json"
"github.com/luxfi/log"
validators "github.com/luxfi/validators"
@@ -4,9 +4,9 @@
package signer
import (
"encoding/json"
"errors"
"github.com/go-json-experiment/json"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/formatting"
)
+1 -1
View File
@@ -4,9 +4,9 @@
package signer
import (
"encoding/json"
"errors"
"github.com/go-json-experiment/json"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/formatting"
)
@@ -4,9 +4,9 @@
package signer
import (
"encoding/json"
"errors"
"github.com/go-json-experiment/json"
"github.com/luxfi/formatting"
)
+1 -1
View File
@@ -4,10 +4,10 @@
package status
import (
"encoding/json"
"errors"
"fmt"
"github.com/go-json-experiment/json"
"github.com/luxfi/node/vms/components/verify"
)
@@ -4,10 +4,10 @@
package status
import (
"encoding/json"
"math"
"testing"
"github.com/go-json-experiment/json"
"github.com/stretchr/testify/require"
)
+1 -1
View File
@@ -4,10 +4,10 @@
package status
import (
"encoding/json"
"errors"
"fmt"
"github.com/go-json-experiment/json"
"github.com/luxfi/node/vms/components/verify"
)
+1 -1
View File
@@ -4,10 +4,10 @@
package status
import (
"encoding/json"
"math"
"testing"
"github.com/go-json-experiment/json"
"github.com/stretchr/testify/require"
)
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"errors"
"math"
"testing"
@@ -397,7 +398,7 @@ func TestAddPermissionlessPrimaryDelegatorSerialization(t *testing.T) {
}
unsignedComplexAddPrimaryTx.InitRuntime(rt2)
unsignedComplexAddPrimaryTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddPrimaryTx, "", "\t")
unsignedComplexAddPrimaryTxJSONBytes, err := json.Marshal(unsignedComplexAddPrimaryTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
@@ -926,7 +927,7 @@ func TestAddPermissionlessNetDelegatorSerialization(t *testing.T) {
}
unsignedComplexAddNetTx.InitRuntime(rt3)
unsignedComplexAddNetTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddNetTx, "", "\t")
unsignedComplexAddNetTxJSONBytes, err := json.Marshal(unsignedComplexAddNetTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
+3 -2
View File
@@ -6,7 +6,8 @@ package txs
import (
"github.com/luxfi/runtime"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -250,7 +251,7 @@ func TestBaseTxSerialization(t *testing.T) {
}
unsignedComplexBaseTx.InitRuntime(rt3)
unsignedComplexBaseTxJSONBytes, err := json.MarshalIndent(unsignedComplexBaseTx, "", "\t")
unsignedComplexBaseTxJSONBytes, err := json.Marshal(unsignedComplexBaseTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
@@ -5,7 +5,8 @@ package txs
import (
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -354,7 +355,7 @@ func TestConvertNetworkToL1TxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
test.tx.InitRuntime(rt)
txJSON, err := json.MarshalIndent(test.tx, "", "\t")
txJSON, err := json.Marshal(test.tx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(string(test.expectedJSON), string(txJSON))
})
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -203,7 +204,7 @@ func TestDisableL1ValidatorTxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
unsignedTx.InitRuntime(rt)
txJSON, err := json.MarshalIndent(unsignedTx, "", "\t")
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(string(disableL1ValidatorTxJSON), string(txJSON))
}
+3 -2
View File
@@ -5,7 +5,8 @@ package fee
import (
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -43,7 +44,7 @@ func TestTxComplexity_Individual(t *testing.T) {
// If the test fails, logging the transaction can be helpful for
// debugging.
txJSON, err := json.MarshalIndent(tx, "", "\t")
txJSON, err := json.Marshal(tx, jsontext.WithIndent("\t"))
require.NoError(err)
t.Log(string(txJSON))
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -201,7 +202,7 @@ func TestIncreaseL1ValidatorBalanceTxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
unsignedTx.InitRuntime(rt)
txJSON, err := json.MarshalIndent(unsignedTx, "", "\t")
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(string(increaseL1ValidatorBalanceTxJSON), string(txJSON))
}
@@ -5,7 +5,8 @@ package txs
import (
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -221,7 +222,7 @@ func TestRegisterL1ValidatorTxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
unsignedTx.InitRuntime(rt)
txJSON, err := json.MarshalIndent(unsignedTx, "", "\t")
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(string(registerL1ValidatorTxJSON), string(txJSON))
}
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"errors"
"testing"
@@ -292,7 +293,7 @@ func TestRemoveChainValidatorTxSerialization(t *testing.T) {
}
unsignedComplexRemoveValidatorTx.InitRuntime(rt3)
unsignedComplexRemoveValidatorTxJSONBytes, err := json.MarshalIndent(unsignedComplexRemoveValidatorTx, "", "\t")
unsignedComplexRemoveValidatorTxJSONBytes, err := json.Marshal(unsignedComplexRemoveValidatorTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/stretchr/testify/require"
@@ -192,7 +193,7 @@ func TestSetL1ValidatorWeightTxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
unsignedTx.InitRuntime(rt)
txJSON, err := json.MarshalIndent(unsignedTx, "", "\t")
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(string(setL1ValidatorWeightTxJSON), string(txJSON))
}
@@ -6,7 +6,8 @@ package txs
import (
"github.com/luxfi/runtime"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/luxfi/mock/gomock"
@@ -296,7 +297,7 @@ func TestTransferChainOwnershipTxSerialization(t *testing.T) {
}
unsignedComplexTransferChainOwnershipTx.InitRuntime(rt3)
unsignedComplexTransferChainOwnershipTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransferChainOwnershipTx, "", "\t")
unsignedComplexTransferChainOwnershipTxJSONBytes, err := json.Marshal(unsignedComplexTransferChainOwnershipTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
@@ -4,7 +4,8 @@
package txs
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"testing"
"github.com/luxfi/runtime"
@@ -336,7 +337,7 @@ func TestTransformChainTxSerialization(t *testing.T) {
}
unsignedComplexTransformTx.InitRuntime(rt3)
unsignedComplexTransformTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransformTx, "", "\t")
unsignedComplexTransformTxJSONBytes, err := json.Marshal(unsignedComplexTransformTx, jsontext.WithIndent("\t"))
require.NoError(err)
require.JSONEq(`{
"networkID": 1,
+1 -1
View File
@@ -6,7 +6,7 @@ package zap
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"fmt"
"net"
+1 -2
View File
@@ -4,8 +4,7 @@
package types
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/luxfi/formatting"
)
+1 -1
View File
@@ -4,9 +4,9 @@
package types
import (
"encoding/json"
"testing"
"github.com/go-json-experiment/json"
"github.com/stretchr/testify/require"
)
+1 -1
View File
@@ -4,7 +4,7 @@
package xvm
import (
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/luxfi/node/vms/xvm/config"
"github.com/luxfi/node/vms/xvm/network"
+1 -1
View File
@@ -4,12 +4,12 @@
package xvm
import (
"encoding/json"
"errors"
"fmt"
"math"
"net/http"
"github.com/go-json-experiment/json"
"github.com/luxfi/consensus/core/choices"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/database"
+1 -1
View File
@@ -4,11 +4,11 @@
package xvm
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/go-json-experiment/json"
"github.com/luxfi/address"
"github.com/luxfi/formatting"
"github.com/luxfi/ids"
+1 -1
View File
@@ -5,7 +5,7 @@ package xvm
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"errors"
"sync"
"testing"
+1 -1
View File
@@ -5,7 +5,7 @@ package xvm
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"sync"
"testing"
@@ -10,7 +10,7 @@ package main
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"flag"
"fmt"
"log"
@@ -9,7 +9,7 @@ package main
import (
"context"
"encoding/json"
"github.com/go-json-experiment/json"
"flag"
"fmt"
"log"
@@ -6,7 +6,8 @@ package main
import (
"context"
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"fmt"
"log"
"time"
@@ -96,7 +97,7 @@ func main() {
if err != nil {
log.Fatalf("failed to create RegisterL1Validator message: %s\n", err)
}
addressedCallPayloadJSON, err := json.MarshalIndent(addressedCallPayload, "", "\t")
addressedCallPayloadJSON, err := json.Marshal(addressedCallPayload, jsontext.WithIndent("\t"))
if err != nil {
log.Fatalf("failed to marshal RegisterL1Validator message: %s\n", err)
}
@@ -6,7 +6,8 @@ package main
import (
"context"
"encoding/hex"
"encoding/json"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"log"
"time"
@@ -73,7 +74,7 @@ func main() {
if err != nil {
log.Fatalf("failed to create L1ValidatorWeight message: %s\n", err)
}
addressedCallPayloadJSON, err := json.MarshalIndent(addressedCallPayload, "", "\t")
addressedCallPayloadJSON, err := json.Marshal(addressedCallPayload, jsontext.WithIndent("\t"))
if err != nil {
log.Fatalf("failed to marshal L1ValidatorWeight message: %s\n", err)
}