Skip to content

Commit

Permalink
fix: ui signle-file compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 committed Dec 12, 2024
1 parent c2b9d56 commit 8a0cf81
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Filemap",
"gibibytes",
"scarb",
"skiplist"
"skiplist",
"testsingle"
]
}
2 changes: 1 addition & 1 deletion api/src/handlers/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::instrument;
use super::types::CompilationRequest;

const DEFAULT_SCARB_TOML: &str = r#"[package]
name = "test"
name = "___testsingle"
version = "0.1.0"
[dependencies]
Expand Down
38 changes: 23 additions & 15 deletions plugin/src/features/Compilation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,19 @@ const Compilation: React.FC<CompilationProps> = ({ setAccordian }) => {
});

throw new Error("Cairo Compilation Request Failed");
} else {
await remixClient.call(
"notification" as any,
"toast",
"Cairo compilation request successful"
);
}

await writeResultsToArtifacts(resultJson);
await remixClient.call(
"notification" as any,
"toast",
"Cairo compilation request successful"
);

try {
await writeResultsToArtifacts(resultJson);
} catch (e) {
console.log("error writing to artifacts: ", e);
}

setIsCompiling(false);
return resultJson;
Expand All @@ -402,33 +406,35 @@ const Compilation: React.FC<CompilationProps> = ({ setAccordian }) => {

// First pass to collect artifacts
for (const file of compileResult.artifacts) {
const basePath = file.real_path.replace(".compiled_contract_class.json", "").replace(".contract_class.json", "");
if (!file.file_name.endsWith(".compiled_contract_class.json") && !file.file_name.endsWith(".contract_class.json")) continue;

const basePath = file.file_name.replace(".compiled_contract_class.json", "").replace(".contract_class.json", "").replace("___testsingle_", "");

if (!(basePath in contractToArtifacts)) {
contractToArtifacts[basePath] = { casm: "", sierra: "" };
}

if (file.real_path.endsWith(".sierra.json")) {
if (file.file_name.endsWith(".contract_class.json")) {
contractToArtifacts[basePath].sierra = file.file_content;
} else if (file.real_path.endsWith(".casm.json")) {
} else if (file.file_name.endsWith(".compiled_contract_class.json")) {
contractToArtifacts[basePath].casm = file.file_content;
}
}

// Create or update contracts
const updatedContracts: Contract[] = [];
for (const [path, artifacts] of Object.entries(contractToArtifacts)) {
for (const [name, artifacts] of Object.entries(contractToArtifacts)) {
const sierraContent = JSON.parse(artifacts.sierra);
const casmContent = JSON.parse(artifacts.casm);
const name = path.split("/").at(-1) ?? path;

const classHash = artifacts.sierra;
const classHash = hash.computeContractClassHash(sierraContent);

const compiledClassHash = hash.computeCompiledClassHash(casmContent);
const sierraClassHash = hash.computeSierraContractClassHash(sierraContent);

// Create new contract
const newContract: Contract = {
name,
path,
abi: sierraContent.abi,
sierra: artifacts.sierra,
casm: casmContent,
Expand All @@ -443,8 +449,10 @@ const Compilation: React.FC<CompilationProps> = ({ setAccordian }) => {
updatedContracts.push(newContract);
}

console.log(updatedContracts);

// Update contracts state with filtered + new contracts
setContracts([...updatedContracts, ...contracts.filter((c: Contract) => !updatedContracts.some((uc: Contract) => uc.path === c.path))]);
setContracts([...updatedContracts, ...contracts.filter((c: Contract) => !updatedContracts.some((uc: Contract) => uc.name === c.name && uc.classHash === c.classHash))]);

// Write artifacts to files
for (const file of compileResult.artifacts) {
Expand Down
1 change: 0 additions & 1 deletion plugin/src/utils/types/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface Contract {
sierra: any;
casm: CairoAssembly;
abi: Abi;
path: string;
deployedInfo: Array<{
address: string;
chainId: constants.StarknetChainId;
Expand Down
2 changes: 1 addition & 1 deletion scarb-test/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "test"
name = "_test"
version = "0.1.0"

[dependencies]
Expand Down

0 comments on commit 8a0cf81

Please sign in to comment.