diff --git a/chain-test/src/unit/GalaJSONSerializer.ts b/chain-test/src/unit/GalaJSONSerializer.ts index 056916dec6..1128a02db6 100644 --- a/chain-test/src/unit/GalaJSONSerializer.ts +++ b/chain-test/src/unit/GalaJSONSerializer.ts @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { plainToInstance } from "class-transformer"; import * as Logger from "fabric-contract-api/lib/logger"; import { serializeValue } from "../serialize"; @@ -150,17 +149,10 @@ export default class GalaJSONSerializer { jsonForValidation = value; return { value, jsonForValidation }; } else if (schema.type === "object") { - logger.debug(`${loggerPrefix} fromBuffer assuming data as object`); - // so this implies we have some json that should be formed up as an object - // need to get the constructor - const cnstr = fullschema.components.schemas[schema.$id].cnstr; - if (cnstr) { - logger.debug(`${loggerPrefix} fromBuffer handling data as object`); - jsonForValidation = JSON.parse(stringData); - value = plainToInstance(cnstr, jsonForValidation); - return { value, jsonForValidation }; - } - logger.debug(`${loggerPrefix} no known constructor`); + logger.debug(`${loggerPrefix} fromBuffer handling data as JSON object`); + jsonForValidation = JSON.parse(stringData); + value = jsonForValidation; + return { value, jsonForValidation }; } else if (schema.type === "array") { jsonForValidation = JSON.parse(stringData); diff --git a/chaincode/src/contracts/GalaTransaction.ts b/chaincode/src/contracts/GalaTransaction.ts index 5a8841c88a..a6629e2c9b 100644 --- a/chaincode/src/contracts/GalaTransaction.ts +++ b/chaincode/src/contracts/GalaTransaction.ts @@ -356,6 +356,19 @@ function GalaTransaction( // Ensure this is an actual HLF transaction. // If this annotation is missing, you cannot call the chaincode method Transaction(isWrite)(target, propertyKey); + + // Overwrite all Reflect metadata types. Fabric stores them by method name, + // so duplicate method names across contracts can get the wrong type. + // Strict serialization is applied in GalaTransaction via parseValidDTO. + // Fabric's generic object schema is sufficient here. + const transactions = + (Reflect.getMetadata("fabric:transactions", target) as + | { name?: string; parameters?: { schema?: unknown }[] }[] + | undefined) ?? []; + const transaction = transactions.find((entry) => entry.name === propertyKey); + for (const parameter of transaction?.parameters ?? []) { + parameter.schema = { type: "object" }; + } }; } diff --git a/chaincode/src/utils/GalaJSONSerializer.ts b/chaincode/src/utils/GalaJSONSerializer.ts index fda39c6c03..cd60ae4924 100644 --- a/chaincode/src/utils/GalaJSONSerializer.ts +++ b/chaincode/src/utils/GalaJSONSerializer.ts @@ -13,7 +13,6 @@ * limitations under the License. */ import { serialize } from "@gala-chain/api"; -import { plainToInstance } from "class-transformer"; import * as Logger from "fabric-contract-api/lib/logger"; /* @@ -147,17 +146,10 @@ export default class GalaJSONSerializer { jsonForValidation = value; return { value, jsonForValidation }; } else if (schema.type === "object") { - logger.debug(`${loggerPrefix} fromBuffer assuming data as object`); - // so this implies we have some json that should be formed up as an object - // need to get the constructor - const cnstr = fullschema.components.schemas[schema.$id].cnstr; - if (cnstr) { - logger.debug(`${loggerPrefix} fromBuffer handling data as object`); - jsonForValidation = JSON.parse(stringData); - value = plainToInstance(cnstr, jsonForValidation); - return { value, jsonForValidation }; - } - logger.debug(`${loggerPrefix} no known constructor`); + logger.debug(`${loggerPrefix} fromBuffer handling data as JSON object`); + jsonForValidation = JSON.parse(stringData); + value = jsonForValidation; + return { value, jsonForValidation }; } else if (schema.type === "array") { jsonForValidation = JSON.parse(stringData);