Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions chain-test/src/unit/GalaJSONSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions chaincode/src/contracts/GalaTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ function GalaTransaction<In extends ChainCallDTO, Out>(
// 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" };
}
};
}

Expand Down
16 changes: 4 additions & 12 deletions chaincode/src/utils/GalaJSONSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/*
Expand Down Expand Up @@ -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);

Expand Down
Loading