-
Notifications
You must be signed in to change notification settings - Fork 59
/
HttpNode.ts
32 lines (29 loc) · 1.17 KB
/
HttpNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { readFile } from 'fs/promises';
import HttpBrowser from './Http';
import { Aci, CompileResult } from './Base';
import { Encoded } from '../../utils/encoder';
import getFileSystem from './getFileSystem';
/**
* Contract Compiler over HTTP for Nodejs
*
* Inherits CompilerHttp and implements `compile`, `validate` methods
* @category contract
* @example CompilerHttpNode('COMPILER_URL')
*/
export default class CompilerHttpNode extends HttpBrowser {
override async compile(path: string): CompileResult {
const fileSystem = await getFileSystem(path);
const sourceCode = await readFile(path, 'utf8');
return this.compileBySourceCode(sourceCode, fileSystem);
}
override async generateAci(path: string): Promise<Aci> {
const fileSystem = await getFileSystem(path);
const sourceCode = await readFile(path, 'utf8');
return this.generateAciBySourceCode(sourceCode, fileSystem);
}
override async validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean> {
const fileSystem = await getFileSystem(path);
const sourceCode = await readFile(path, 'utf8');
return this.validateBySourceCode(bytecode, sourceCode, fileSystem);
}
}