diff --git a/cmd/soroban-rpc/internal/methods/simulate_transaction.go b/cmd/soroban-rpc/internal/methods/simulate_transaction.go index 2a26b08a..0fc318c2 100644 --- a/cmd/soroban-rpc/internal/methods/simulate_transaction.go +++ b/cmd/soroban-rpc/internal/methods/simulate_transaction.go @@ -398,13 +398,15 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge switch request.Format { case FormatJSON: - simResp.TransactionDataJSON, err = xdr2json.ConvertBytes( - xdr.SorobanTransactionData{}, - result.TransactionData) - if err != nil { - return SimulateTransactionResponse{ - Error: err.Error(), - LatestLedger: latestLedger, + if len(result.TransactionData) > 0 { + simResp.TransactionDataJSON, err = xdr2json.ConvertBytes( + xdr.SorobanTransactionData{}, + result.TransactionData) + if err != nil { + return SimulateTransactionResponse{ + Error: err.Error(), + LatestLedger: latestLedger, + } } } diff --git a/cmd/soroban-rpc/internal/xdr2json/conversion.go b/cmd/soroban-rpc/internal/xdr2json/conversion.go index 7992ab9b..828b3145 100644 --- a/cmd/soroban-rpc/internal/xdr2json/conversion.go +++ b/cmd/soroban-rpc/internal/xdr2json/conversion.go @@ -27,24 +27,20 @@ import ( // and returns the raw JSON-formatted serialization of that object. // It can be unmarshalled to a proper JSON structure, but the raw bytes are // returned to avoid unnecessary round-trips. If there is an -// error, it returns an empty string. +// error, it returns an empty JSON object. // // The `xdr` object does not need to actually be initialized/valid: // we only use it to determine the name of the structure. We could just // accept a string, but that would make mistakes likelier than passing the // structure itself (by reference). -func ConvertBytes(xdr interface{}, field []byte) (json.RawMessage, error) { - if len(field) == 0 { - return []byte(""), nil - } - +func ConvertBytes(xdr interface{}, field []byte) ([]byte, error) { xdrTypeName := reflect.TypeOf(xdr).Name() return convertAnyBytes(xdrTypeName, field) } // ConvertInterface takes a valid XDR object (`xdr`) and returns // the raw JSON-formatted serialization of that object. If there is an -// error, it returns an empty string. +// error, it returns an empty JSON object. // // Unlike `ConvertBytes`, the value here needs to be valid and // serializable. @@ -52,7 +48,7 @@ func ConvertInterface(xdr encoding.BinaryMarshaler) (json.RawMessage, error) { xdrTypeName := reflect.TypeOf(xdr).Name() data, err := xdr.MarshalBinary() if err != nil { - return []byte(""), errors.Wrapf(err, "failed to serialize XDR type '%s'", xdrTypeName) + return []byte("{}"), errors.Wrapf(err, "failed to serialize XDR type '%s'", xdrTypeName) } return convertAnyBytes(xdrTypeName, data)