@5ive-tech/sdk 1.1.10 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/FiveSDK.d.ts +3 -4
- package/dist/FiveSDK.js +47 -5
- package/dist/accounts/index.js +3 -2
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +5 -5
- package/dist/bin/gen-types.js +0 -0
- package/dist/compiler/BytecodeCompiler.d.ts +1 -7
- package/dist/compiler/BytecodeCompiler.js +105 -44
- package/dist/config/ProgramIdResolver.d.ts +1 -6
- package/dist/config/ProgramIdResolver.js +11 -16
- package/dist/config/VmClusterConfigResolver.d.ts +27 -0
- package/dist/config/VmClusterConfigResolver.js +111 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/accounts.js +7 -1
- package/dist/modules/admin.js +25 -12
- package/dist/modules/deploy.js +62 -23
- package/dist/modules/execute.js +71 -37
- package/dist/modules/vm-state.js +6 -1
- package/dist/program/FunctionBuilder.d.ts +8 -0
- package/dist/program/FunctionBuilder.js +18 -5
- package/dist/project/config.js +0 -1
- package/dist/testing/TestRunner.js +6 -1
- package/dist/types.d.ts +19 -2
- package/dist/utils/abi.d.ts +4 -0
- package/dist/utils/abi.js +3 -0
- package/dist/utils/transaction.d.ts +22 -0
- package/dist/utils/transaction.js +94 -12
- package/dist/wasm/compiler/CompilationLogic.d.ts +0 -5
- package/dist/wasm/compiler/CompilationLogic.js +45 -163
- package/dist/wasm/compiler/FiveCompiler.d.ts +0 -5
- package/dist/wasm/compiler/FiveCompiler.js +0 -6
- package/dist/wasm/compiler/utils.d.ts +34 -1
- package/dist/wasm/compiler/utils.js +223 -5
- package/package.json +4 -3
package/dist/types.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export interface ProjectConfig {
|
|
|
18
18
|
keypairPath?: string;
|
|
19
19
|
optimizations?: ProjectOptimizations;
|
|
20
20
|
dependencies?: ProjectDependency[];
|
|
21
|
-
multiFileMode?: boolean;
|
|
22
21
|
wasm?: {
|
|
23
22
|
loader?: 'auto' | 'node' | 'bundler';
|
|
24
23
|
modulePaths?: string[];
|
|
@@ -80,12 +79,15 @@ export interface CompilationResult {
|
|
|
80
79
|
metadata?: CompilationMetadata;
|
|
81
80
|
errors?: CompilationError[];
|
|
82
81
|
warnings?: CompilationWarning[];
|
|
82
|
+
diagnostics?: CompilationError[];
|
|
83
83
|
disassembly?: string[];
|
|
84
84
|
metrics?: CompilationMetrics;
|
|
85
85
|
metricsReport?: CompilationMetricsReport;
|
|
86
86
|
fiveFile?: FiveCompiledFile;
|
|
87
87
|
publicFunctionNames?: string[];
|
|
88
88
|
functionNames?: string[] | FunctionNameEntry[];
|
|
89
|
+
formattedErrorsTerminal?: string;
|
|
90
|
+
formattedErrorsJson?: string;
|
|
89
91
|
}
|
|
90
92
|
export interface CompilationMetadata {
|
|
91
93
|
sourceFile: string;
|
|
@@ -113,7 +115,16 @@ export interface CompilationError {
|
|
|
113
115
|
category?: string;
|
|
114
116
|
description?: string;
|
|
115
117
|
location?: any;
|
|
116
|
-
suggestions?: string
|
|
118
|
+
suggestions?: Array<string | {
|
|
119
|
+
message: string;
|
|
120
|
+
explanation?: string;
|
|
121
|
+
confidence?: number;
|
|
122
|
+
codeSuggestion?: string;
|
|
123
|
+
}>;
|
|
124
|
+
sourceLine?: string;
|
|
125
|
+
sourceSnippet?: string;
|
|
126
|
+
rendered?: string;
|
|
127
|
+
raw?: any;
|
|
117
128
|
}
|
|
118
129
|
export interface CompilationWarning {
|
|
119
130
|
type: string;
|
|
@@ -332,12 +343,18 @@ export interface FiveCompiledFile {
|
|
|
332
343
|
}
|
|
333
344
|
export interface FiveFunction {
|
|
334
345
|
name: string;
|
|
346
|
+
index?: number;
|
|
335
347
|
parameters: FiveParameter[];
|
|
336
348
|
returnType?: FiveType;
|
|
337
349
|
}
|
|
338
350
|
export interface FiveParameter {
|
|
339
351
|
name: string;
|
|
340
352
|
type: FiveType;
|
|
353
|
+
param_type?: FiveType;
|
|
354
|
+
optional?: boolean;
|
|
355
|
+
is_account?: boolean;
|
|
356
|
+
isAccount?: boolean;
|
|
357
|
+
attributes?: string[];
|
|
341
358
|
}
|
|
342
359
|
export type FiveType = string;
|
|
343
360
|
export interface FunctionNameEntry {
|
package/dist/utils/abi.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ export interface NormalizedABIFunction {
|
|
|
4
4
|
parameters: Array<{
|
|
5
5
|
name: string;
|
|
6
6
|
type: string;
|
|
7
|
+
param_type?: string;
|
|
7
8
|
optional?: boolean;
|
|
9
|
+
is_account?: boolean;
|
|
10
|
+
isAccount?: boolean;
|
|
11
|
+
attributes?: string[];
|
|
8
12
|
}>;
|
|
9
13
|
returnType?: string;
|
|
10
14
|
accounts?: any[];
|
package/dist/utils/abi.js
CHANGED
|
@@ -20,8 +20,11 @@ export function normalizeAbiFunctions(abiFunctions) {
|
|
|
20
20
|
parameters: parameters.map((param, paramIdx) => ({
|
|
21
21
|
name: param.name ?? `param${paramIdx}`,
|
|
22
22
|
type: param.type ?? param.param_type ?? param.paramType ?? '',
|
|
23
|
+
param_type: param.param_type ?? param.paramType,
|
|
23
24
|
optional: param.optional ?? false,
|
|
25
|
+
is_account: param.is_account ?? param.isAccount ?? false,
|
|
24
26
|
isAccount: param.isAccount ?? param.is_account ?? false,
|
|
27
|
+
attributes: Array.isArray(param.attributes) ? [...param.attributes] : [],
|
|
25
28
|
})),
|
|
26
29
|
returnType: func.returnType ?? func.return_type,
|
|
27
30
|
accounts: func.accounts ?? [],
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
export declare const SDK_COMMITMENTS: {
|
|
2
|
+
readonly WRITE: "confirmed";
|
|
3
|
+
readonly READ: "finalized";
|
|
4
|
+
readonly CONFIRM: "finalized";
|
|
5
|
+
};
|
|
1
6
|
export declare function pollForConfirmation(connection: any, signature: string, commitment?: string, timeoutMs?: number, debug?: boolean): Promise<{
|
|
2
7
|
success: boolean;
|
|
3
8
|
err?: any;
|
|
4
9
|
error?: string;
|
|
5
10
|
}>;
|
|
11
|
+
export declare function confirmTransactionRobust(connection: any, signature: string, options?: {
|
|
12
|
+
commitment?: string;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
debug?: boolean;
|
|
15
|
+
blockhash?: string;
|
|
16
|
+
lastValidBlockHeight?: number;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
err?: any;
|
|
20
|
+
error?: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function getAccountInfoWithRetry(connection: any, pubkey: any, options?: {
|
|
23
|
+
commitment?: string;
|
|
24
|
+
retries?: number;
|
|
25
|
+
delayMs?: number;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
}): Promise<any | null>;
|
|
@@ -1,6 +1,40 @@
|
|
|
1
|
+
export const SDK_COMMITMENTS = {
|
|
2
|
+
WRITE: "confirmed",
|
|
3
|
+
READ: "finalized",
|
|
4
|
+
CONFIRM: "finalized",
|
|
5
|
+
};
|
|
6
|
+
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
7
|
+
const DEFAULT_RETRY_DELAY_MS = 700;
|
|
8
|
+
async function sleep(ms) {
|
|
9
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
function backoffDelayMs(baseMs, attempt) {
|
|
12
|
+
const exp = Math.min(attempt, 6);
|
|
13
|
+
const raw = baseMs * (2 ** exp);
|
|
14
|
+
const jitter = Math.floor(raw * (0.15 * Math.random()));
|
|
15
|
+
return raw + jitter;
|
|
16
|
+
}
|
|
17
|
+
function normalizeCommitment(commitment) {
|
|
18
|
+
if (commitment === "finalized")
|
|
19
|
+
return "finalized";
|
|
20
|
+
if (commitment === "processed")
|
|
21
|
+
return "processed";
|
|
22
|
+
return "confirmed";
|
|
23
|
+
}
|
|
24
|
+
function statusMeetsCommitment(status, confirmations, target) {
|
|
25
|
+
if (target === "processed") {
|
|
26
|
+
return !!status || (confirmations ?? 0) >= 0;
|
|
27
|
+
}
|
|
28
|
+
if (target === "confirmed") {
|
|
29
|
+
return status === "confirmed" || status === "finalized" || (confirmations ?? 0) >= 1;
|
|
30
|
+
}
|
|
31
|
+
// finalized must be explicitly finalized; confirmations count is insufficient.
|
|
32
|
+
return status === "finalized";
|
|
33
|
+
}
|
|
1
34
|
export async function pollForConfirmation(connection, signature, commitment = "confirmed", timeoutMs = 120000, debug = false) {
|
|
2
35
|
const startTime = Date.now();
|
|
3
|
-
const pollIntervalMs =
|
|
36
|
+
const pollIntervalMs = DEFAULT_POLL_INTERVAL_MS;
|
|
37
|
+
const targetCommitment = normalizeCommitment(commitment);
|
|
4
38
|
if (debug) {
|
|
5
39
|
console.log(`[FiveSDK] Starting confirmation poll with ${timeoutMs}ms timeout`);
|
|
6
40
|
}
|
|
@@ -11,30 +45,36 @@ export async function pollForConfirmation(connection, signature, commitment = "c
|
|
|
11
45
|
console.log(`[FiveSDK] Confirmation status: ${JSON.stringify(confirmationStatus.value)}`);
|
|
12
46
|
}
|
|
13
47
|
if (confirmationStatus.value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
48
|
+
const transactionError = confirmationStatus.value.err;
|
|
49
|
+
if (transactionError) {
|
|
50
|
+
if (debug) {
|
|
51
|
+
console.log(`[FiveSDK] Transaction error: ${JSON.stringify(transactionError)}`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
err: transactionError,
|
|
56
|
+
error: JSON.stringify(transactionError),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (statusMeetsCommitment(confirmationStatus.value.confirmationStatus, confirmationStatus.value.confirmations, targetCommitment)) {
|
|
60
|
+
const succeeded = true;
|
|
18
61
|
if (debug) {
|
|
19
62
|
console.log(`[FiveSDK] Transaction confirmed after ${Date.now() - startTime}ms${succeeded ? '' : ' (with error)'}`);
|
|
20
|
-
if (transactionError) {
|
|
21
|
-
console.log(`[FiveSDK] Transaction error: ${JSON.stringify(transactionError)}`);
|
|
22
|
-
}
|
|
23
63
|
}
|
|
24
64
|
return {
|
|
25
65
|
success: succeeded,
|
|
26
|
-
err:
|
|
27
|
-
error:
|
|
66
|
+
err: undefined,
|
|
67
|
+
error: undefined,
|
|
28
68
|
};
|
|
29
69
|
}
|
|
30
70
|
}
|
|
31
|
-
await
|
|
71
|
+
await sleep(pollIntervalMs);
|
|
32
72
|
}
|
|
33
73
|
catch (error) {
|
|
34
74
|
if (debug) {
|
|
35
75
|
console.log(`[FiveSDK] Polling error: ${error instanceof Error ? error.message : String(error)}`);
|
|
36
76
|
}
|
|
37
|
-
await
|
|
77
|
+
await sleep(pollIntervalMs);
|
|
38
78
|
}
|
|
39
79
|
}
|
|
40
80
|
const elapsed = Date.now() - startTime;
|
|
@@ -46,3 +86,45 @@ export async function pollForConfirmation(connection, signature, commitment = "c
|
|
|
46
86
|
error: `Transaction confirmation timeout after ${elapsed}ms. Signature: ${signature}`,
|
|
47
87
|
};
|
|
48
88
|
}
|
|
89
|
+
export async function confirmTransactionRobust(connection, signature, options = {}) {
|
|
90
|
+
const commitment = options.commitment || SDK_COMMITMENTS.CONFIRM;
|
|
91
|
+
const timeoutMs = options.timeoutMs || 120000;
|
|
92
|
+
const debug = options.debug || false;
|
|
93
|
+
try {
|
|
94
|
+
const confirmArg = options.blockhash && typeof options.lastValidBlockHeight === "number"
|
|
95
|
+
? {
|
|
96
|
+
signature,
|
|
97
|
+
blockhash: options.blockhash,
|
|
98
|
+
lastValidBlockHeight: options.lastValidBlockHeight,
|
|
99
|
+
}
|
|
100
|
+
: signature;
|
|
101
|
+
const confirmation = await connection.confirmTransaction(confirmArg, commitment);
|
|
102
|
+
const err = confirmation?.value?.err;
|
|
103
|
+
if (!err) {
|
|
104
|
+
return { success: true };
|
|
105
|
+
}
|
|
106
|
+
return { success: false, err, error: JSON.stringify(err) };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (debug) {
|
|
110
|
+
console.log(`[FiveSDK] confirmTransaction threw, falling back to polling: ${error instanceof Error ? error.message : String(error)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return pollForConfirmation(connection, signature, commitment, timeoutMs, debug);
|
|
114
|
+
}
|
|
115
|
+
export async function getAccountInfoWithRetry(connection, pubkey, options = {}) {
|
|
116
|
+
const commitment = options.commitment || SDK_COMMITMENTS.READ;
|
|
117
|
+
const retries = options.retries ?? 2;
|
|
118
|
+
const delayMs = options.delayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
119
|
+
const debug = options.debug || false;
|
|
120
|
+
let info = await connection.getAccountInfo(pubkey, commitment);
|
|
121
|
+
for (let attempt = 0; !info && attempt < retries; attempt++) {
|
|
122
|
+
const waitMs = backoffDelayMs(delayMs, attempt);
|
|
123
|
+
if (debug) {
|
|
124
|
+
console.log(`[FiveSDK] getAccountInfo retry ${attempt + 1}/${retries}, waiting ${waitMs}ms`);
|
|
125
|
+
}
|
|
126
|
+
await sleep(waitMs);
|
|
127
|
+
info = await connection.getAccountInfo(pubkey, commitment);
|
|
128
|
+
}
|
|
129
|
+
return info;
|
|
130
|
+
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { CompilationOptions, CompilationResult } from "../../types.js";
|
|
2
2
|
import { CompilationContext } from "./types.js";
|
|
3
3
|
export declare function compile(ctx: CompilationContext, source: string, options?: any): Promise<any>;
|
|
4
|
-
export declare function compileModules(ctx: CompilationContext, mainSource: string, modules: Array<{
|
|
5
|
-
name: string;
|
|
6
|
-
source: string;
|
|
7
|
-
}>, options?: any): Promise<any>;
|
|
8
4
|
export declare function compileFile(ctx: CompilationContext, options: CompilationOptions): Promise<CompilationResult>;
|
|
9
5
|
export declare function compileWithDiscovery(ctx: CompilationContext, entryPoint: string, options?: any): Promise<any>;
|
|
10
|
-
export declare function compileModulesExplicit(ctx: CompilationContext, moduleFiles: string[], entryPoint: string, options?: any): Promise<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile } from "fs/promises";
|
|
2
|
-
import { createCompilerError, extractMetrics, extractAbi } from "./utils.js";
|
|
2
|
+
import { createCompilerError, extractMetrics, extractAbi, extractFormattedErrors, extractDiagnostics, } from "./utils.js";
|
|
3
3
|
export async function compile(ctx, source, options) {
|
|
4
4
|
if (!ctx.compiler) {
|
|
5
5
|
throw createCompilerError("Compiler not initialized");
|
|
@@ -25,7 +25,8 @@ export async function compile(ctx, source, options) {
|
|
|
25
25
|
.with_metrics(includeMetrics)
|
|
26
26
|
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
27
27
|
.with_metrics_format(metricsFormat)
|
|
28
|
-
.with_error_format(errorFormat)
|
|
28
|
+
.with_error_format(errorFormat)
|
|
29
|
+
.with_source_file(options?.sourceFile || "input.v");
|
|
29
30
|
result = ctx.compiler.compile(source, compilationOptions);
|
|
30
31
|
if (result.compiler_errors && result.compiler_errors.length > 0) {
|
|
31
32
|
ctx.logger.debug(`WASM returned ${result.compiler_errors.length} compiler errors`);
|
|
@@ -50,6 +51,8 @@ export async function compile(ctx, source, options) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
54
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
55
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
53
56
|
if (result.success && result.bytecode) {
|
|
54
57
|
return {
|
|
55
58
|
success: true,
|
|
@@ -58,79 +61,33 @@ export async function compile(ctx, source, options) {
|
|
|
58
61
|
metadata: result.metadata,
|
|
59
62
|
metrics: metricsPayload,
|
|
60
63
|
metricsReport: metricsPayload,
|
|
64
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
65
|
+
formattedErrorsJson: formattedErrors.json,
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
69
|
return {
|
|
65
70
|
success: false,
|
|
66
|
-
errors:
|
|
71
|
+
errors: diagnostics,
|
|
72
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
73
|
+
diagnostics,
|
|
67
74
|
metadata: result.metadata,
|
|
68
75
|
metrics: metricsPayload,
|
|
69
76
|
metricsReport: metricsPayload,
|
|
77
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
78
|
+
formattedErrorsJson: formattedErrors.json,
|
|
70
79
|
};
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
catch (error) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
83
|
+
if (error &&
|
|
84
|
+
typeof error === "object" &&
|
|
85
|
+
error.code === "COMPILER_ERROR") {
|
|
86
|
+
throw error;
|
|
76
87
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export async function compileModules(ctx, mainSource, modules, options) {
|
|
83
|
-
if (!ctx.compiler) {
|
|
84
|
-
throw createCompilerError("Compiler not initialized");
|
|
85
|
-
}
|
|
86
|
-
const startTime = Date.now();
|
|
87
|
-
try {
|
|
88
|
-
let WasmCompilationOptions = ctx.WasmCompilationOptions;
|
|
89
|
-
if (!WasmCompilationOptions && ctx.wasmModuleRef) {
|
|
90
|
-
WasmCompilationOptions = ctx.wasmModuleRef.WasmCompilationOptions;
|
|
91
|
-
}
|
|
92
|
-
const metricsFormat = options?.metricsFormat || "json";
|
|
93
|
-
const includeMetrics = options?.includeMetrics || Boolean(options?.metricsOutput);
|
|
94
|
-
const errorFormat = options?.errorFormat || "terminal";
|
|
95
|
-
const comprehensiveMetrics = options?.comprehensiveMetrics || false;
|
|
96
|
-
const compilationOptions = new WasmCompilationOptions()
|
|
97
|
-
.with_mode(options?.target || "deployment")
|
|
98
|
-
.with_optimization_level(options?.optimizationLevel || "production")
|
|
99
|
-
.with_v2_preview(true)
|
|
100
|
-
.with_constraint_cache(false)
|
|
101
|
-
.with_enhanced_errors(true)
|
|
102
|
-
.with_metrics(includeMetrics)
|
|
103
|
-
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
104
|
-
.with_metrics_format(metricsFormat)
|
|
105
|
-
.with_error_format(errorFormat);
|
|
106
|
-
const result = ctx.compiler.compile_multi(mainSource, modules, compilationOptions);
|
|
107
|
-
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
108
|
-
if (result.success && result.bytecode) {
|
|
109
|
-
return {
|
|
110
|
-
success: true,
|
|
111
|
-
bytecode: result.bytecode,
|
|
112
|
-
abi: extractAbi(result, ctx.logger),
|
|
113
|
-
metadata: result.metadata,
|
|
114
|
-
metrics: metricsPayload,
|
|
115
|
-
metricsReport: metricsPayload,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
errors: result.compiler_errors || [],
|
|
122
|
-
metadata: result.metadata,
|
|
123
|
-
metrics: metricsPayload,
|
|
124
|
-
metricsReport: metricsPayload,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error);
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
const compilationTime = Date.now() - startTime;
|
|
133
|
-
ctx.logger.debug(`Multi-file compilation completed in ${compilationTime}ms`);
|
|
88
|
+
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error, {
|
|
89
|
+
phase: "compile",
|
|
90
|
+
});
|
|
134
91
|
}
|
|
135
92
|
}
|
|
136
93
|
export async function compileFile(ctx, options) {
|
|
@@ -233,60 +190,17 @@ export async function compileFile(ctx, options) {
|
|
|
233
190
|
}
|
|
234
191
|
const compilationTime = Date.now() - startTime;
|
|
235
192
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
const jsonErrors = result.format_all_json
|
|
240
|
-
? result.format_all_json()
|
|
241
|
-
: null;
|
|
242
|
-
if (jsonErrors) {
|
|
243
|
-
const parsedErrors = JSON.parse(jsonErrors);
|
|
244
|
-
convertedErrors = parsedErrors.map((error) => ({
|
|
245
|
-
type: "enhanced",
|
|
246
|
-
...error,
|
|
247
|
-
code: error.code || "E0000",
|
|
248
|
-
severity: error.severity || "error",
|
|
249
|
-
category: error.category || "compilation",
|
|
250
|
-
message: error.message || "Unknown error",
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
convertedErrors = [
|
|
255
|
-
{
|
|
256
|
-
type: "enhanced",
|
|
257
|
-
code: "E0004",
|
|
258
|
-
severity: "error",
|
|
259
|
-
category: "compilation",
|
|
260
|
-
message: "InvalidScript",
|
|
261
|
-
description: "The script contains syntax or semantic errors",
|
|
262
|
-
location: undefined,
|
|
263
|
-
suggestions: [],
|
|
264
|
-
},
|
|
265
|
-
];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
catch (parseError) {
|
|
269
|
-
ctx.logger.debug("Failed to parse JSON errors from WASM:", parseError);
|
|
270
|
-
convertedErrors = [
|
|
271
|
-
{
|
|
272
|
-
type: "enhanced",
|
|
273
|
-
code: "E0004",
|
|
274
|
-
severity: "error",
|
|
275
|
-
category: "compilation",
|
|
276
|
-
message: "InvalidScript",
|
|
277
|
-
description: "Compilation failed with enhanced error system",
|
|
278
|
-
location: undefined,
|
|
279
|
-
suggestions: [],
|
|
280
|
-
},
|
|
281
|
-
];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
193
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
194
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
284
195
|
const compilationResult = {
|
|
285
196
|
success: result.success,
|
|
286
197
|
bytecode: result.bytecode ? new Uint8Array(result.bytecode) : undefined,
|
|
287
198
|
abi: result.abi || undefined,
|
|
288
|
-
errors:
|
|
289
|
-
warnings:
|
|
199
|
+
errors: diagnostics,
|
|
200
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
201
|
+
diagnostics,
|
|
202
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
203
|
+
formattedErrorsJson: formattedErrors.json,
|
|
290
204
|
metrics: {
|
|
291
205
|
compilationTime: result.compilation_time || compilationTime,
|
|
292
206
|
bytecodeSize: result.bytecode_size || 0,
|
|
@@ -353,9 +267,12 @@ export async function compileWithDiscovery(ctx, entryPoint, options) {
|
|
|
353
267
|
.with_metrics(includeMetrics)
|
|
354
268
|
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
355
269
|
.with_metrics_format(metricsFormat)
|
|
356
|
-
.with_error_format(errorFormat)
|
|
270
|
+
.with_error_format(errorFormat)
|
|
271
|
+
.with_source_file(entryPoint);
|
|
357
272
|
const result = ctx.compiler.compileMultiWithDiscovery(entryPoint, compilationOptions);
|
|
358
273
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
274
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
275
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
359
276
|
if (result.success && result.bytecode) {
|
|
360
277
|
return {
|
|
361
278
|
success: true,
|
|
@@ -364,68 +281,33 @@ export async function compileWithDiscovery(ctx, entryPoint, options) {
|
|
|
364
281
|
metadata: result.metadata,
|
|
365
282
|
metrics: metricsPayload,
|
|
366
283
|
metricsReport: metricsPayload,
|
|
284
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
285
|
+
formattedErrorsJson: formattedErrors.json,
|
|
367
286
|
};
|
|
368
287
|
}
|
|
369
288
|
else {
|
|
370
289
|
return {
|
|
371
290
|
success: false,
|
|
372
|
-
errors:
|
|
291
|
+
errors: diagnostics,
|
|
292
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
293
|
+
diagnostics,
|
|
373
294
|
metadata: result.metadata,
|
|
374
295
|
metrics: metricsPayload,
|
|
375
296
|
metricsReport: metricsPayload,
|
|
297
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
298
|
+
formattedErrorsJson: formattedErrors.json,
|
|
376
299
|
};
|
|
377
300
|
}
|
|
378
301
|
}
|
|
379
302
|
catch (error) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!ctx.compiler) {
|
|
385
|
-
throw createCompilerError("Compiler not initialized");
|
|
386
|
-
}
|
|
387
|
-
try {
|
|
388
|
-
let WasmCompilationOptions = ctx.WasmCompilationOptions;
|
|
389
|
-
if (!WasmCompilationOptions && ctx.wasmModuleRef) {
|
|
390
|
-
WasmCompilationOptions = ctx.wasmModuleRef.WasmCompilationOptions;
|
|
303
|
+
if (error &&
|
|
304
|
+
typeof error === "object" &&
|
|
305
|
+
error.code === "COMPILER_ERROR") {
|
|
306
|
+
throw error;
|
|
391
307
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const compilationOptions = new WasmCompilationOptions()
|
|
397
|
-
.with_mode(options?.target || "deployment")
|
|
398
|
-
.with_optimization_level(options?.optimizationLevel || "production")
|
|
399
|
-
.with_v2_preview(true)
|
|
400
|
-
.with_constraint_cache(false)
|
|
401
|
-
.with_enhanced_errors(true)
|
|
402
|
-
.with_metrics(includeMetrics)
|
|
403
|
-
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
404
|
-
.with_metrics_format(metricsFormat)
|
|
405
|
-
.with_error_format(errorFormat);
|
|
406
|
-
const result = ctx.compiler.compileModules(moduleFiles, entryPoint, compilationOptions);
|
|
407
|
-
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
408
|
-
if (result.success && result.bytecode) {
|
|
409
|
-
return {
|
|
410
|
-
success: true,
|
|
411
|
-
bytecode: result.bytecode,
|
|
412
|
-
abi: result.abi,
|
|
413
|
-
metadata: result.metadata,
|
|
414
|
-
metrics: metricsPayload,
|
|
415
|
-
metricsReport: metricsPayload,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
return {
|
|
420
|
-
success: false,
|
|
421
|
-
errors: result.compiler_errors || [],
|
|
422
|
-
metadata: result.metadata,
|
|
423
|
-
metrics: metricsPayload,
|
|
424
|
-
metricsReport: metricsPayload,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
catch (error) {
|
|
429
|
-
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error);
|
|
308
|
+
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error, {
|
|
309
|
+
phase: "compileWithDiscovery",
|
|
310
|
+
entryPoint,
|
|
311
|
+
});
|
|
430
312
|
}
|
|
431
313
|
}
|
|
@@ -17,13 +17,8 @@ export declare class FiveCompiler {
|
|
|
17
17
|
initialize(): Promise<void>;
|
|
18
18
|
private getContext;
|
|
19
19
|
compile(source: string, options?: any): Promise<any>;
|
|
20
|
-
compileModules(mainSource: string, modules: Array<{
|
|
21
|
-
name: string;
|
|
22
|
-
source: string;
|
|
23
|
-
}>, options?: any): Promise<any>;
|
|
24
20
|
compileFile(options: CompilationOptions): Promise<CompilationResult>;
|
|
25
21
|
compileWithDiscovery(entryPoint: string, options?: any): Promise<any>;
|
|
26
|
-
compileModulesExplicit(moduleFiles: string[], entryPoint: string, options?: any): Promise<any>;
|
|
27
22
|
generateABI(sourceCode: string): Promise<any>;
|
|
28
23
|
extractAccountDefinitions(sourceCode: string): Promise<any>;
|
|
29
24
|
extractFunctionSignatures(sourceCode: string): Promise<any>;
|
|
@@ -121,18 +121,12 @@ export class FiveCompiler {
|
|
|
121
121
|
async compile(source, options) {
|
|
122
122
|
return CompilationLogic.compile(this.getContext(), source, options);
|
|
123
123
|
}
|
|
124
|
-
async compileModules(mainSource, modules, options) {
|
|
125
|
-
return CompilationLogic.compileModules(this.getContext(), mainSource, modules, options);
|
|
126
|
-
}
|
|
127
124
|
async compileFile(options) {
|
|
128
125
|
return CompilationLogic.compileFile(this.getContext(), options);
|
|
129
126
|
}
|
|
130
127
|
async compileWithDiscovery(entryPoint, options) {
|
|
131
128
|
return CompilationLogic.compileWithDiscovery(this.getContext(), entryPoint, options);
|
|
132
129
|
}
|
|
133
|
-
async compileModulesExplicit(moduleFiles, entryPoint, options) {
|
|
134
|
-
return CompilationLogic.compileModulesExplicit(this.getContext(), moduleFiles, entryPoint, options);
|
|
135
|
-
}
|
|
136
130
|
// --- ABI & Extraction ---
|
|
137
131
|
async generateABI(sourceCode) {
|
|
138
132
|
return AbiLogic.generateABI(this.getContext(), sourceCode);
|
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import { CLIError } from "../../types.js";
|
|
2
|
-
export
|
|
2
|
+
export interface NormalizedCompilationSuggestion {
|
|
3
|
+
message: string;
|
|
4
|
+
explanation?: string;
|
|
5
|
+
confidence?: number;
|
|
6
|
+
codeSuggestion?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NormalizedCompilationDiagnostic {
|
|
9
|
+
type: string;
|
|
10
|
+
code: string;
|
|
11
|
+
severity: string;
|
|
12
|
+
category: string;
|
|
13
|
+
message: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
line?: number;
|
|
16
|
+
column?: number;
|
|
17
|
+
sourceLocation?: string;
|
|
18
|
+
location?: any;
|
|
19
|
+
suggestion?: string;
|
|
20
|
+
suggestions?: NormalizedCompilationSuggestion[];
|
|
21
|
+
sourceLine?: string;
|
|
22
|
+
sourceSnippet?: string;
|
|
23
|
+
rendered?: string;
|
|
24
|
+
raw?: any;
|
|
25
|
+
}
|
|
26
|
+
export interface FormattedErrors {
|
|
27
|
+
terminal?: string;
|
|
28
|
+
json?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function createCompilerError(message: string, cause?: Error, details?: Record<string, unknown>): CLIError;
|
|
31
|
+
export declare function extractFormattedErrors(result: any): FormattedErrors;
|
|
32
|
+
export declare function normalizeDiagnostic(error: any): NormalizedCompilationDiagnostic;
|
|
33
|
+
export declare function extractDiagnostics(result: any, logger?: {
|
|
34
|
+
debug?: (...args: any[]) => void;
|
|
35
|
+
}): NormalizedCompilationDiagnostic[];
|
|
3
36
|
export declare function extractMetrics(result: any, defaultFormat: string): {
|
|
4
37
|
format: string;
|
|
5
38
|
exported: string;
|