Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): register namespace labels #3172

Merged
merged 3 commits into from
Sep 12, 2024
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
5 changes: 5 additions & 0 deletions .changeset/metal-brooms-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Along with table and system labels, the MUD deployer now registers namespace labels. Additionally, labels will only be registered if they differ from the underlying resource name.
28 changes: 23 additions & 5 deletions packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensureFunctions } from "./ensureFunctions";
import { ensureModules } from "./ensureModules";
import { ensureNamespaceOwner } from "./ensureNamespaceOwner";
import { debug } from "./debug";
import { resourceToLabel } from "@latticexyz/common";
import { resourceToHex, resourceToLabel } from "@latticexyz/common";
import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { randomBytes } from "crypto";
import { ensureWorldFactory } from "./ensureWorldFactory";
Expand All @@ -19,6 +19,7 @@ import { waitForTransactions } from "./waitForTransactions";
import { ContractArtifact } from "@latticexyz/world/node";
import { World } from "@latticexyz/world";
import { deployCustomWorld } from "./deployCustomWorld";
import { uniqueBy } from "@latticexyz/common/utils";

type DeployOptions = {
config: World;
Expand Down Expand Up @@ -150,9 +151,26 @@ export async function deploy({
modules,
});

const tableTags = tables.map(({ tableId: resourceId, label }) => ({ resourceId, tag: "label", value: label }));
const systemTags = systems.flatMap(({ systemId: resourceId, label, abi, worldAbi }) => [
{ resourceId, tag: "label", value: label },
const namespaceTags = uniqueBy(
[...tables, ...systems]
// only register labels if they differ from the resource ID
.filter(({ namespace, namespaceLabel }) => namespaceLabel !== namespace)
.map(({ namespace, namespaceLabel }) => ({
resourceId: resourceToHex({ type: "namespace", namespace, name: "" }),
tag: "label",
value: namespaceLabel,
})),
(tag) => tag.resourceId,
);

const tableTags = tables
// only register labels if they differ from the resource ID
.filter((table) => table.label !== table.name)
.map(({ tableId: resourceId, label }) => ({ resourceId, tag: "label", value: label }));

const systemTags = systems.flatMap(({ name, systemId: resourceId, label, abi, worldAbi }) => [
// only register labels if they differ from the resource ID
...(label !== name ? [{ resourceId, tag: "label", value: label }] : []),
{ resourceId, tag: "abi", value: abi.join("\n") },
{ resourceId, tag: "worldAbi", value: worldAbi.join("\n") },
]);
Expand All @@ -162,7 +180,7 @@ export async function deploy({
deployerAddress,
libraries,
worldDeploy,
tags: [...tableTags, ...systemTags],
tags: [...namespaceTags, ...tableTags, ...systemTags],
valueToHex: stringToHex,
});

Expand Down
Loading