@alephium/web3 0.2.0-rc.2 → 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 +18 -0
- package/contracts/test/warnings.ral +8 -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 +25 -5
- package/dist/src/api/api-alephium.js +16 -0
- package/dist/src/contract/contract.d.ts +77 -50
- package/dist/src/contract/contract.js +306 -219
- package/dist/src/utils/utils.d.ts +2 -2
- package/dist/src/utils/utils.js +1 -1
- package/gitignore +0 -1
- package/package.json +2 -4
- package/src/api/api-alephium.ts +39 -5
- package/src/contract/contract.ts +405 -314
- package/src/contract/events.ts +2 -2
- package/src/contract/ralph.test.ts +4 -4
- package/src/transaction/status.ts +1 -1
- package/src/utils/subscription.ts +1 -1
- package/src/utils/utils.ts +3 -3
- package/templates/base/package.json +2 -2
- package/templates/react/package.json +2 -2
- package/test/contract.test.ts +48 -13
- package/test/events.test.ts +13 -8
- package/test/transaction.test.ts +6 -4
|
@@ -311,11 +311,17 @@ export interface CompileContractResult {
|
|
|
311
311
|
fields: FieldsSig;
|
|
312
312
|
functions: FunctionSig[];
|
|
313
313
|
events: EventSig[];
|
|
314
|
+
warnings: string[];
|
|
315
|
+
}
|
|
316
|
+
export interface CompileProjectResult {
|
|
317
|
+
contracts: CompileContractResult[];
|
|
318
|
+
scripts: CompileScriptResult[];
|
|
314
319
|
}
|
|
315
320
|
export interface CompileScriptResult {
|
|
316
321
|
bytecodeTemplate: string;
|
|
317
322
|
fields: FieldsSig;
|
|
318
323
|
functions: FunctionSig[];
|
|
324
|
+
warnings: string[];
|
|
319
325
|
}
|
|
320
326
|
export interface Confirmed {
|
|
321
327
|
/** @format block-hash */
|
|
@@ -409,7 +415,6 @@ export interface Destination {
|
|
|
409
415
|
export declare type DiscoveryAction = Reachable | Unreachable;
|
|
410
416
|
export interface EventSig {
|
|
411
417
|
name: string;
|
|
412
|
-
signature: string;
|
|
413
418
|
fieldNames: string[];
|
|
414
419
|
fieldTypes: string[];
|
|
415
420
|
}
|
|
@@ -417,9 +422,9 @@ export interface FetchResponse {
|
|
|
417
422
|
blocks: BlockEntry[][];
|
|
418
423
|
}
|
|
419
424
|
export interface FieldsSig {
|
|
420
|
-
signature: string;
|
|
421
425
|
names: string[];
|
|
422
426
|
types: string[];
|
|
427
|
+
isMutable: boolean[];
|
|
423
428
|
}
|
|
424
429
|
export interface FixedAssetOutput {
|
|
425
430
|
/** @format int32 */
|
|
@@ -438,9 +443,12 @@ export interface FixedAssetOutput {
|
|
|
438
443
|
}
|
|
439
444
|
export interface FunctionSig {
|
|
440
445
|
name: string;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
446
|
+
usePreapprovedAssets: boolean;
|
|
447
|
+
useAssetsInContract: boolean;
|
|
448
|
+
isPublic: boolean;
|
|
449
|
+
paramNames: string[];
|
|
450
|
+
paramTypes: string[];
|
|
451
|
+
paramIsMutable: boolean[];
|
|
444
452
|
returnTypes: string[];
|
|
445
453
|
}
|
|
446
454
|
export interface Group {
|
|
@@ -522,6 +530,9 @@ export interface Penalty {
|
|
|
522
530
|
value: number;
|
|
523
531
|
type: string;
|
|
524
532
|
}
|
|
533
|
+
export interface Project {
|
|
534
|
+
code: string;
|
|
535
|
+
}
|
|
525
536
|
export interface Reachable {
|
|
526
537
|
peers: string[];
|
|
527
538
|
type: string;
|
|
@@ -1334,6 +1345,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1334
1345
|
* @request POST:/contracts/compile-contract
|
|
1335
1346
|
*/
|
|
1336
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>;
|
|
1337
1357
|
/**
|
|
1338
1358
|
* No description
|
|
1339
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,79 +1,106 @@
|
|
|
1
1
|
import { NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
3
|
import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
|
|
4
|
+
import { CompileContractResult, CompileScriptResult } from '../api/api-alephium';
|
|
5
|
+
declare type FieldsSig = node.FieldsSig;
|
|
6
|
+
declare type EventSig = node.EventSig;
|
|
7
|
+
declare type FunctionSig = node.FunctionSig;
|
|
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
|
+
}
|
|
4
20
|
declare class SourceFile {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
static
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
62
|
+
readonly functions: FunctionSig[];
|
|
63
|
+
constructor(functions: FunctionSig[]);
|
|
32
64
|
abstract buildByteCodeToDeploy(initialFields?: Fields): string;
|
|
65
|
+
publicFunctions(): string[];
|
|
66
|
+
usingPreapprovedAssetsFunctions(): string[];
|
|
67
|
+
usingAssetsInContractFunctions(): string[];
|
|
33
68
|
}
|
|
34
|
-
export declare class Contract extends
|
|
69
|
+
export declare class Contract extends Artifact {
|
|
35
70
|
readonly bytecode: string;
|
|
36
71
|
readonly codeHash: string;
|
|
37
|
-
readonly fieldsSig:
|
|
38
|
-
readonly eventsSig:
|
|
39
|
-
constructor(
|
|
40
|
-
static checkCodeType(fileName: string, contractStr: string): void;
|
|
41
|
-
private static loadContractStr;
|
|
42
|
-
static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
|
|
43
|
-
private static compile;
|
|
72
|
+
readonly fieldsSig: FieldsSig;
|
|
73
|
+
readonly eventsSig: EventSig[];
|
|
74
|
+
constructor(bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
|
|
44
75
|
static fromJson(artifact: any): Contract;
|
|
76
|
+
static fromCompileResult(result: CompileContractResult): Contract;
|
|
45
77
|
static fromArtifactFile(path: string): Promise<Contract>;
|
|
46
|
-
fetchState(
|
|
78
|
+
fetchState(address: string, group: number): Promise<ContractState>;
|
|
47
79
|
toString(): string;
|
|
48
80
|
toState(fields: Fields, asset: Asset, address?: string): ContractState;
|
|
49
81
|
static randomAddress(): string;
|
|
50
82
|
private _test;
|
|
51
|
-
testPublicMethod(
|
|
52
|
-
testPrivateMethod(
|
|
83
|
+
testPublicMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
|
|
84
|
+
testPrivateMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
|
|
53
85
|
toApiFields(fields?: Fields): node.Val[];
|
|
54
86
|
toApiArgs(funcName: string, args?: Arguments): node.Val[];
|
|
55
87
|
getMethodIndex(funcName: string): number;
|
|
56
88
|
toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
|
|
57
89
|
toTestContract(funcName: string, params: TestContractParams): node.TestContract;
|
|
58
|
-
static fromCodeHash(codeHash: string): Promise<Contract>;
|
|
59
|
-
static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
|
|
60
90
|
fromApiContractState(state: node.ContractState): Promise<ContractState>;
|
|
61
|
-
static ContractCreatedEvent:
|
|
62
|
-
static ContractDestroyedEvent:
|
|
91
|
+
static ContractCreatedEvent: EventSig;
|
|
92
|
+
static ContractDestroyedEvent: EventSig;
|
|
63
93
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
|
|
64
94
|
fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
|
|
65
95
|
paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
|
|
66
96
|
transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
|
|
67
97
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
68
98
|
}
|
|
69
|
-
export declare class Script extends
|
|
99
|
+
export declare class Script extends Artifact {
|
|
70
100
|
readonly bytecodeTemplate: string;
|
|
71
|
-
readonly fieldsSig:
|
|
72
|
-
constructor(
|
|
73
|
-
static
|
|
74
|
-
private static loadContractStr;
|
|
75
|
-
static fromSource(provider: NodeProvider, path: string): Promise<Script>;
|
|
76
|
-
private static compile;
|
|
101
|
+
readonly fieldsSig: FieldsSig;
|
|
102
|
+
constructor(bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
|
|
103
|
+
static fromCompileResult(result: CompileScriptResult): Script;
|
|
77
104
|
static fromJson(artifact: any): Script;
|
|
78
105
|
static fromArtifactFile(path: string): Promise<Script>;
|
|
79
106
|
toString(): string;
|
|
@@ -107,7 +134,7 @@ export interface ContractState {
|
|
|
107
134
|
initialStateHash?: string;
|
|
108
135
|
codeHash: string;
|
|
109
136
|
fields: Fields;
|
|
110
|
-
fieldsSig:
|
|
137
|
+
fieldsSig: FieldsSig;
|
|
111
138
|
asset: Asset;
|
|
112
139
|
}
|
|
113
140
|
export interface TestContractParams {
|