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

Fix tact injection #60

Merged
merged 3 commits into from
Mar 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
4 changes: 2 additions & 2 deletions src/check-prerequisites.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import path from "path";
import { binaryPath } from "./binaries";
import { getFuncVersions } from "./fetch-func-versions";
import { getSupportedVersions } from "./fetch-compiler-versions";
export async function checkPrerequisites() {
const missingEnvVars = [
"VERIFIER_ID",
Expand All @@ -19,7 +19,7 @@ export async function checkPrerequisites() {

if (missingEnvVars) throw new Error("Missing env vars: " + missingEnvVars);

const funcVersions = await getFuncVersions();
const { funcVersions } = await getSupportedVersions();

const missingFiles = funcVersions!
.map((versionDir: string) => [
Expand Down
20 changes: 20 additions & 0 deletions src/fetch-compiler-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from "axios";
let versions: {
funcVersions: string[];
tactVersions: string[];
} | null = null;

export async function getSupportedVersions() {
if (!versions) {
const { data } = await axios.get(
"https://raw.githubusercontent.com/ton-community/contract-verifier-config/main/config.json",
{ responseType: "json" },
);
versions = {
funcVersions: data.funcVersions,
tactVersions: data.tactVersions,
};
}

return versions;
}
14 changes: 0 additions & 14 deletions src/fetch-func-versions.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { TactSourceVerifier, FileSystem } from "./source-verifier/tact-source-ve
import { TonReaderClientImpl } from "./ton-reader-client";
import { getLatestVerified } from "./latest-known-contracts";
import { DeployController } from "./deploy-controller";
import axios from "axios";
import { getFuncVersions } from "./fetch-func-versions";
import { getSupportedVersions } from "./fetch-compiler-versions";

const app = express();
app.use(idMiddleware());
Expand Down Expand Up @@ -207,7 +206,7 @@ app.get("/hc", (req, res) => {
},
);

await getFuncVersions();
await getSupportedVersions();

if (process.env.NODE_ENV === "production") checkPrerequisites();

Expand Down
9 changes: 8 additions & 1 deletion src/source-verifier/tact-source-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PackageFileFormat } from "tact-1.1.5";
import type { verify as VerifyFunction } from "tact-1.1.5";
import path from "path";
import { timeoutPromise } from "../utils";
import { getSupportedVersions } from "../fetch-compiler-versions";

export type FileSystem = {
readFile: (path: string) => Promise<Buffer>;
Expand Down Expand Up @@ -34,6 +35,12 @@ export class TactSourceVerifier implements SourceVerifier {

const output: string[] = [];

const { tactVersions } = await getSupportedVersions();

if (!tactVersions.includes(pkgParsed.compiler.version)) {
throw new Error("Unsupported tact version: " + pkgParsed.compiler.version);
}

const verify: typeof VerifyFunction = await import(`tact-${pkgParsed.compiler.version}`)
.then((m) => m.verify)
.catch((e) => {
Expand Down Expand Up @@ -67,7 +74,7 @@ export class TactSourceVerifier implements SourceVerifier {

const sources = await Promise.all(
Object.entries(v.files)
.filter(([filename]) => !filename.match(/\.(fif|boc|ts|md|pkg)/))
.filter(([filename]) => filename.match(/\.(abi|tact|pkg)$/) && !filename.match(/\.\./))
.map(async ([filename, contentB64]) => {
const writePath = path.join(payload.tmpDir, filename);
let content = Buffer.from(contentB64, "base64").toString("utf-8");
Expand Down
Loading