platformvm/txs: emit [N]byte fields as JSON arrays for v1 RPC parity

RegisterL1ValidatorTx (and other txs reachable through Service.GetTx,
Service.GetBlock, Service.GetBlockByHeight) contains
ProofOfPossession [bls.SignatureLen]byte and PublicKey [bls.PublicKeyLen]byte.
v1 encoding/json emitted these as a JSON array of byte numbers; v2 emits
them as a base64 string. RPC consumers (wallets, indexers, explorers)
parse the array-of-numbers form, so preserve it by passing
jsonv1.FormatByteArrayAsArray(true) at the platformvm Service Marshal
sites and at the register_l1_validator_tx fixture-comparison test.
This commit is contained in:
Hanzo AI
2026-06-06 23:06:52 -07:00
parent 8cf6c53246
commit 5c5db2e3fc
2 changed files with 6 additions and 4 deletions
+4 -3
View File
@@ -14,6 +14,7 @@ import (
"time"
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"github.com/luxfi/log"
validators "github.com/luxfi/validators"
@@ -1504,7 +1505,7 @@ func (s *Service) GetTx(_ *http.Request, args *apitypes.GetTxArgs, response *api
}
}
response.Tx, err = json.Marshal(result)
response.Tx, err = json.Marshal(result, jsonv1.FormatByteArrayAsArray(true))
return err
}
@@ -2029,7 +2030,7 @@ func (s *Service) GetBlock(_ *http.Request, args *apitypes.GetBlockArgs, respons
}
}
response.Block, err = json.Marshal(result)
response.Block, err = json.Marshal(result, jsonv1.FormatByteArrayAsArray(true))
return err
}
@@ -2071,7 +2072,7 @@ func (s *Service) GetBlockByHeight(_ *http.Request, args *apitypes.GetBlockByHei
}
}
response.Block, err = json.Marshal(result)
response.Block, err = json.Marshal(result, jsonv1.FormatByteArrayAsArray(true))
return err
}
@@ -6,6 +6,7 @@ package txs
import (
"encoding/hex"
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"github.com/go-json-experiment/json/jsontext"
"testing"
@@ -222,7 +223,7 @@ func TestRegisterL1ValidatorTxSerialization(t *testing.T) {
rt := consensustest.Runtime(t, constants.PlatformChainID)
unsignedTx.InitRuntime(rt)
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"))
txJSON, err := json.Marshal(unsignedTx, jsontext.WithIndent("\t"), jsonv1.FormatByteArrayAsArray(true))
require.NoError(err)
require.JSONEq(string(registerL1ValidatorTxJSON), string(txJSON))
}