@alephium/web3 0.2.0-rc.4 → 0.2.0-rc.5
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/contracts/add/add.ral +5 -6
- package/contracts/greeter/greeter.ral +2 -2
- package/contracts/greeter/greeter_interface.ral +1 -0
- package/contracts/greeter_main.ral +0 -2
- package/contracts/main.ral +0 -2
- package/contracts/sub/sub.ral +1 -0
- package/contracts/test/metadata.ral +1 -0
- package/contracts/test/warnings.ral +1 -0
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +16 -0
- package/dist/src/api/api-alephium.js +16 -0
- package/dist/src/contract/contract.d.ts +65 -47
- package/dist/src/contract/contract.js +296 -234
- package/gitignore +0 -1
- package/package.json +2 -4
- package/src/api/api-alephium.ts +30 -0
- package/src/contract/contract.ts +377 -350
- package/templates/base/package.json +2 -2
- package/templates/react/package.json +2 -2
- package/test/contract.test.ts +32 -19
- package/test/events.test.ts +13 -8
- package/test/transaction.test.ts +5 -3
|
@@ -313,6 +313,10 @@ export interface CompileContractResult {
|
|
|
313
313
|
events: EventSig[];
|
|
314
314
|
warnings: string[];
|
|
315
315
|
}
|
|
316
|
+
export interface CompileProjectResult {
|
|
317
|
+
contracts: CompileContractResult[];
|
|
318
|
+
scripts: CompileScriptResult[];
|
|
319
|
+
}
|
|
316
320
|
export interface CompileScriptResult {
|
|
317
321
|
bytecodeTemplate: string;
|
|
318
322
|
fields: FieldsSig;
|
|
@@ -526,6 +530,9 @@ export interface Penalty {
|
|
|
526
530
|
value: number;
|
|
527
531
|
type: string;
|
|
528
532
|
}
|
|
533
|
+
export interface Project {
|
|
534
|
+
code: string;
|
|
535
|
+
}
|
|
529
536
|
export interface Reachable {
|
|
530
537
|
peers: string[];
|
|
531
538
|
type: string;
|
|
@@ -1338,6 +1345,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1338
1345
|
* @request POST:/contracts/compile-contract
|
|
1339
1346
|
*/
|
|
1340
1347
|
postContractsCompileContract: (data: Contract, params?: RequestParams) => Promise<CompileContractResult>;
|
|
1348
|
+
/**
|
|
1349
|
+
* No description
|
|
1350
|
+
*
|
|
1351
|
+
* @tags Contracts
|
|
1352
|
+
* @name PostContractsCompileProject
|
|
1353
|
+
* @summary Compile a project
|
|
1354
|
+
* @request POST:/contracts/compile-project
|
|
1355
|
+
*/
|
|
1356
|
+
postContractsCompileProject: (data: Project, params?: RequestParams) => Promise<CompileProjectResult>;
|
|
1341
1357
|
/**
|
|
1342
1358
|
* No description
|
|
1343
1359
|
*
|
|
@@ -901,6 +901,22 @@ class Api extends HttpClient {
|
|
|
901
901
|
format: 'json',
|
|
902
902
|
...params
|
|
903
903
|
}).then(convertHttpResponse),
|
|
904
|
+
/**
|
|
905
|
+
* No description
|
|
906
|
+
*
|
|
907
|
+
* @tags Contracts
|
|
908
|
+
* @name PostContractsCompileProject
|
|
909
|
+
* @summary Compile a project
|
|
910
|
+
* @request POST:/contracts/compile-project
|
|
911
|
+
*/
|
|
912
|
+
postContractsCompileProject: (data, params = {}) => this.request({
|
|
913
|
+
path: `/contracts/compile-project`,
|
|
914
|
+
method: 'POST',
|
|
915
|
+
body: data,
|
|
916
|
+
type: ContentType.Json,
|
|
917
|
+
format: 'json',
|
|
918
|
+
...params
|
|
919
|
+
}).then(convertHttpResponse),
|
|
904
920
|
/**
|
|
905
921
|
* No description
|
|
906
922
|
*
|
|
@@ -1,71 +1,92 @@
|
|
|
1
1
|
import { NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
3
|
import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
|
|
4
|
-
|
|
5
|
-
readonly dirs: string[];
|
|
6
|
-
readonly dirPath: string;
|
|
7
|
-
readonly contractPath: string;
|
|
8
|
-
readonly artifactPath: string;
|
|
9
|
-
constructor(dirs: string[], fileName: string);
|
|
10
|
-
}
|
|
4
|
+
import { CompileContractResult, CompileScriptResult } from '../api/api-alephium';
|
|
11
5
|
declare type FieldsSig = node.FieldsSig;
|
|
12
6
|
declare type EventSig = node.EventSig;
|
|
13
7
|
declare type FunctionSig = node.FunctionSig;
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
declare enum SourceType {
|
|
9
|
+
Contract = 0,
|
|
10
|
+
Script = 1,
|
|
11
|
+
AbstractContract = 2,
|
|
12
|
+
Interface = 3
|
|
13
|
+
}
|
|
14
|
+
declare class TypedMatcher<T extends SourceType> {
|
|
15
|
+
matcher: RegExp;
|
|
16
|
+
type: T;
|
|
17
|
+
constructor(pattern: string, type: T);
|
|
18
|
+
match(str: string): number;
|
|
19
|
+
}
|
|
20
|
+
declare class SourceFile {
|
|
21
|
+
type: SourceType;
|
|
22
|
+
contractPath: string;
|
|
23
|
+
sourceCode: string;
|
|
24
|
+
sourceCodeHash: string;
|
|
25
|
+
getArtifactPath(artifactsRootPath: string): string;
|
|
26
|
+
constructor(type: SourceType, sourceCode: string, contractPath: string);
|
|
27
|
+
}
|
|
28
|
+
declare class Compiled<T extends Artifact> {
|
|
29
|
+
sourceFile: SourceFile;
|
|
30
|
+
artifact: T;
|
|
31
|
+
warnings: string[];
|
|
32
|
+
constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
|
|
33
|
+
}
|
|
34
|
+
export declare class Project {
|
|
35
|
+
sourceFiles: SourceFile[];
|
|
36
|
+
contracts: Compiled<Contract>[];
|
|
37
|
+
scripts: Compiled<Script>[];
|
|
38
|
+
readonly contractsRootPath: string;
|
|
39
|
+
readonly artifactsRootPath: string;
|
|
40
|
+
readonly nodeProvider: NodeProvider;
|
|
41
|
+
static currentProject: Project;
|
|
42
|
+
static readonly abstractContractMatcher: TypedMatcher<SourceType>;
|
|
43
|
+
static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
|
|
44
|
+
static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
|
|
45
|
+
static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
|
|
46
|
+
static readonly matchers: TypedMatcher<SourceType>[];
|
|
47
|
+
private constructor();
|
|
48
|
+
private getContractPath;
|
|
49
|
+
private static checkCompilerWarnings;
|
|
50
|
+
static contract(path: string, errorOnWarnings?: boolean, ignoreUnusedConstantsWarnings?: boolean): Contract;
|
|
51
|
+
static script(path: string, errorOnWarnings?: boolean, ignoreUnusedConstantsWarnings?: boolean): Script;
|
|
52
|
+
private saveArtifactsToFile;
|
|
53
|
+
contractByCodeHash(codeHash: string): Contract;
|
|
54
|
+
private saveProjectArtifactToFile;
|
|
55
|
+
private static compile;
|
|
56
|
+
private static loadArtifacts;
|
|
57
|
+
private static loadSourceFile;
|
|
58
|
+
private static loadSourceFiles;
|
|
59
|
+
static build(provider: NodeProvider, contractsRootPath?: string, artifactsRootPath?: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export declare abstract class Artifact {
|
|
16
62
|
readonly functions: FunctionSig[];
|
|
17
|
-
|
|
18
|
-
static readonly contractRegex: RegExp;
|
|
19
|
-
static readonly interfaceRegex: RegExp;
|
|
20
|
-
static readonly scriptRegex: RegExp;
|
|
21
|
-
private static _artifactCache;
|
|
22
|
-
static artifactCacheCapacity: number;
|
|
23
|
-
protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
|
|
24
|
-
protected static _putArtifactToCache(contract: Contract): void;
|
|
25
|
-
constructor(sourceCodeSha256: string, functions: FunctionSig[]);
|
|
26
|
-
protected static _artifactsFolder(): string;
|
|
27
|
-
static getSourceFile(path: string, _dirs: string[]): SourceFile;
|
|
28
|
-
protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
|
|
29
|
-
protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
|
|
30
|
-
static checkFileNameExtension(fileName: string): void;
|
|
31
|
-
protected static _from<T extends {
|
|
32
|
-
sourceCodeSha256: string;
|
|
33
|
-
}>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string, errorOnWarnings: boolean, ignoreUnusedConstantsWarnings: boolean) => Promise<T>, errorOnWarnings: boolean, ignoreUnusedConstantsWarnings: boolean): Promise<T>;
|
|
34
|
-
protected _saveToFile(sourceFile: SourceFile): Promise<void>;
|
|
63
|
+
constructor(functions: FunctionSig[]);
|
|
35
64
|
abstract buildByteCodeToDeploy(initialFields?: Fields): string;
|
|
36
65
|
publicFunctions(): string[];
|
|
37
66
|
usingPreapprovedAssetsFunctions(): string[];
|
|
38
67
|
usingAssetsInContractFunctions(): string[];
|
|
39
|
-
protected static checkCompilerWarnings(compiled: {
|
|
40
|
-
warnings: string[];
|
|
41
|
-
}, errorOnWarnings: boolean, ignoreUnusedConstantsWarnings: boolean): void;
|
|
42
68
|
}
|
|
43
|
-
export declare class Contract extends
|
|
69
|
+
export declare class Contract extends Artifact {
|
|
44
70
|
readonly bytecode: string;
|
|
45
71
|
readonly codeHash: string;
|
|
46
72
|
readonly fieldsSig: FieldsSig;
|
|
47
73
|
readonly eventsSig: EventSig[];
|
|
48
|
-
constructor(
|
|
49
|
-
static checkCodeType(fileName: string, contractStr: string): void;
|
|
50
|
-
private static loadContractStr;
|
|
51
|
-
static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean, ignoreUnusedConstantsWarnings?: boolean): Promise<Contract>;
|
|
52
|
-
private static compile;
|
|
74
|
+
constructor(bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
|
|
53
75
|
static fromJson(artifact: any): Contract;
|
|
76
|
+
static fromCompileResult(result: CompileContractResult): Contract;
|
|
54
77
|
static fromArtifactFile(path: string): Promise<Contract>;
|
|
55
|
-
fetchState(
|
|
78
|
+
fetchState(address: string, group: number): Promise<ContractState>;
|
|
56
79
|
toString(): string;
|
|
57
80
|
toState(fields: Fields, asset: Asset, address?: string): ContractState;
|
|
58
81
|
static randomAddress(): string;
|
|
59
82
|
private _test;
|
|
60
|
-
testPublicMethod(
|
|
61
|
-
testPrivateMethod(
|
|
83
|
+
testPublicMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
|
|
84
|
+
testPrivateMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
|
|
62
85
|
toApiFields(fields?: Fields): node.Val[];
|
|
63
86
|
toApiArgs(funcName: string, args?: Arguments): node.Val[];
|
|
64
87
|
getMethodIndex(funcName: string): number;
|
|
65
88
|
toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
|
|
66
89
|
toTestContract(funcName: string, params: TestContractParams): node.TestContract;
|
|
67
|
-
static fromCodeHash(codeHash: string): Promise<Contract>;
|
|
68
|
-
static getFieldsSig(state: node.ContractState): Promise<FieldsSig>;
|
|
69
90
|
fromApiContractState(state: node.ContractState): Promise<ContractState>;
|
|
70
91
|
static ContractCreatedEvent: EventSig;
|
|
71
92
|
static ContractDestroyedEvent: EventSig;
|
|
@@ -75,14 +96,11 @@ export declare class Contract extends Common {
|
|
|
75
96
|
transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
|
|
76
97
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
77
98
|
}
|
|
78
|
-
export declare class Script extends
|
|
99
|
+
export declare class Script extends Artifact {
|
|
79
100
|
readonly bytecodeTemplate: string;
|
|
80
101
|
readonly fieldsSig: FieldsSig;
|
|
81
|
-
constructor(
|
|
82
|
-
static
|
|
83
|
-
private static loadContractStr;
|
|
84
|
-
static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean, ignoreUnusedConstantsWarnings?: boolean): Promise<Script>;
|
|
85
|
-
private static compile;
|
|
102
|
+
constructor(bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
|
|
103
|
+
static fromCompileResult(result: CompileScriptResult): Script;
|
|
86
104
|
static fromJson(artifact: any): Script;
|
|
87
105
|
static fromArtifactFile(path: string): Promise<Script>;
|
|
88
106
|
toString(): string;
|