@openzeppelin/wizard-stellar 0.1.0
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/LICENSE +661 -0
- package/NOTICE +8 -0
- package/README.md +57 -0
- package/dist/add-pausable.d.ts +4 -0
- package/dist/add-pausable.d.ts.map +1 -0
- package/dist/add-pausable.js +37 -0
- package/dist/add-pausable.js.map +1 -0
- package/dist/api.d.ts +22 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +9 -0
- package/dist/api.js.map +1 -0
- package/dist/build-generic.d.ts +9 -0
- package/dist/build-generic.d.ts.map +1 -0
- package/dist/build-generic.js +15 -0
- package/dist/build-generic.js.map +1 -0
- package/dist/common-options.d.ts +15 -0
- package/dist/common-options.d.ts.map +1 -0
- package/dist/common-options.js +31 -0
- package/dist/common-options.js.map +1 -0
- package/dist/contract.d.ts +91 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +123 -0
- package/dist/contract.js.map +1 -0
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +11 -0
- package/dist/error.js.map +1 -0
- package/dist/fungible.d.ts +24 -0
- package/dist/fungible.d.ts.map +1 -0
- package/dist/fungible.js +264 -0
- package/dist/fungible.js.map +1 -0
- package/dist/generate/alternatives.d.ts +7 -0
- package/dist/generate/alternatives.d.ts.map +1 -0
- package/dist/generate/alternatives.js +27 -0
- package/dist/generate/alternatives.js.map +1 -0
- package/dist/generate/fungible.d.ts +3 -0
- package/dist/generate/fungible.d.ts.map +1 -0
- package/dist/generate/fungible.js +21 -0
- package/dist/generate/fungible.js.map +1 -0
- package/dist/generate/sources.d.ts +16 -0
- package/dist/generate/sources.d.ts.map +1 -0
- package/dist/generate/sources.js +62 -0
- package/dist/generate/sources.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/kind.d.ts +4 -0
- package/dist/kind.d.ts.map +1 -0
- package/dist/kind.js +24 -0
- package/dist/kind.js.map +1 -0
- package/dist/print.d.ts +3 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +257 -0
- package/dist/print.js.map +1 -0
- package/dist/set-access-control.d.ts +15 -0
- package/dist/set-access-control.d.ts.map +1 -0
- package/dist/set-access-control.js +67 -0
- package/dist/set-access-control.js.map +1 -0
- package/dist/set-info.d.ts +10 -0
- package/dist/set-info.d.ts.map +1 -0
- package/dist/set-info.js +13 -0
- package/dist/set-info.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +21 -0
- package/dist/test.js.map +1 -0
- package/dist/utils/convert-strings.d.ts +27 -0
- package/dist/utils/convert-strings.d.ts.map +1 -0
- package/dist/utils/convert-strings.js +81 -0
- package/dist/utils/convert-strings.js.map +1 -0
- package/dist/utils/define-functions.d.ts +5 -0
- package/dist/utils/define-functions.d.ts.map +1 -0
- package/dist/utils/define-functions.js +7 -0
- package/dist/utils/define-functions.js.map +1 -0
- package/dist/utils/format-lines.d.ts +6 -0
- package/dist/utils/format-lines.d.ts.map +1 -0
- package/dist/utils/format-lines.js +28 -0
- package/dist/utils/format-lines.js.map +1 -0
- package/dist/utils/sorted-by.d.ts +2 -0
- package/dist/utils/sorted-by.d.ts.map +1 -0
- package/dist/utils/sorted-by.js +7 -0
- package/dist/utils/sorted-by.js.map +1 -0
- package/dist/utils/version.d.ts +10 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +13 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +33 -0
- package/src/add-pausable.ts +40 -0
- package/src/api.ts +30 -0
- package/src/build-generic.ts +19 -0
- package/src/common-options.ts +38 -0
- package/src/contract.ts +201 -0
- package/src/error.ts +7 -0
- package/src/fungible.ts +300 -0
- package/src/generate/alternatives.ts +32 -0
- package/src/generate/fungible.ts +21 -0
- package/src/generate/sources.ts +75 -0
- package/src/index.ts +24 -0
- package/src/kind.ts +26 -0
- package/src/print.ts +305 -0
- package/src/set-access-control.ts +73 -0
- package/src/set-info.ts +17 -0
- package/src/test.ts +26 -0
- package/src/utils/convert-strings.ts +83 -0
- package/src/utils/define-functions.ts +9 -0
- package/src/utils/format-lines.ts +26 -0
- package/src/utils/sorted-by.ts +3 -0
- package/src/utils/version.ts +10 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The actual latest version to use in links.
|
|
3
|
+
*/
|
|
4
|
+
export declare const contractsVersion = "0.1.0";
|
|
5
|
+
export declare const contractsVersionTag = "v0.1.0";
|
|
6
|
+
/**
|
|
7
|
+
* Semantic version string representing of the minimum compatible version of Contracts to display in output.
|
|
8
|
+
*/
|
|
9
|
+
export declare const compatibleContractsSemver = "^0.1.0";
|
|
10
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,UAAU,CAAC;AACxC,eAAO,MAAM,mBAAmB,WAAyB,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,yBAAyB,WAAW,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compatibleContractsSemver = exports.contractsVersionTag = exports.contractsVersion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The actual latest version to use in links.
|
|
6
|
+
*/
|
|
7
|
+
exports.contractsVersion = '0.1.0';
|
|
8
|
+
exports.contractsVersionTag = `v${exports.contractsVersion}`;
|
|
9
|
+
/**
|
|
10
|
+
* Semantic version string representing of the minimum compatible version of Contracts to display in output.
|
|
11
|
+
*/
|
|
12
|
+
exports.compatibleContractsSemver = '^0.1.0';
|
|
13
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAC3B,QAAA,mBAAmB,GAAG,IAAI,wBAAgB,EAAE,CAAC;AAE1D;;GAEG;AACU,QAAA,yBAAyB,GAAG,QAAQ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openzeppelin/wizard-stellar",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A boilerplate generator to get started with OpenZeppelin Stellar Soroban Contracts",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"ts:main": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"NOTICE",
|
|
12
|
+
"/dist",
|
|
13
|
+
"/src",
|
|
14
|
+
"!**/*.test.*"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepare": "tsc",
|
|
18
|
+
"prepublish": "rimraf dist *.tsbuildinfo",
|
|
19
|
+
"test": "ava",
|
|
20
|
+
"test:update-snapshots": "ava --update-snapshots",
|
|
21
|
+
"test:watch": "ava --watch",
|
|
22
|
+
"version": "node ../../../scripts/bump-changelog.js"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^18.0.0",
|
|
26
|
+
"@types/semver": "^7.5.7",
|
|
27
|
+
"ava": "^6.0.0",
|
|
28
|
+
"rimraf": "^5.0.0",
|
|
29
|
+
"ts-node": "^10.4.0",
|
|
30
|
+
"typescript": "^5.0.0",
|
|
31
|
+
"semver": "^7.6.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getSelfArg } from './common-options';
|
|
2
|
+
import type { ContractBuilder } from './contract';
|
|
3
|
+
import type { Access } from './set-access-control';
|
|
4
|
+
import { requireAccessControl } from './set-access-control';
|
|
5
|
+
import { defineFunctions } from './utils/define-functions';
|
|
6
|
+
|
|
7
|
+
export function addPausable(c: ContractBuilder, access: Access) {
|
|
8
|
+
c.addUseClause('openzeppelin_pausable', 'self', { alias: 'pausable' });
|
|
9
|
+
c.addUseClause('openzeppelin_pausable', 'Pausable');
|
|
10
|
+
|
|
11
|
+
const pausableTrait = {
|
|
12
|
+
name: 'Pausable',
|
|
13
|
+
for: c.name,
|
|
14
|
+
tags: ['contractimpl'],
|
|
15
|
+
section: 'Utils',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
c.addFunction(pausableTrait, functions.paused);
|
|
19
|
+
c.addFunction(pausableTrait, functions.pause);
|
|
20
|
+
c.addFunction(pausableTrait, functions.unpause);
|
|
21
|
+
|
|
22
|
+
requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
|
|
23
|
+
requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const functions = defineFunctions({
|
|
27
|
+
paused: {
|
|
28
|
+
args: [getSelfArg()],
|
|
29
|
+
returns: 'bool',
|
|
30
|
+
code: ['pausable::paused(e)'],
|
|
31
|
+
},
|
|
32
|
+
pause: {
|
|
33
|
+
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
|
|
34
|
+
code: ['pausable::pause(e, &caller)'],
|
|
35
|
+
},
|
|
36
|
+
unpause: {
|
|
37
|
+
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
|
|
38
|
+
code: ['pausable::unpause(e, &caller)'],
|
|
39
|
+
},
|
|
40
|
+
});
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CommonContractOptions } from './common-options';
|
|
2
|
+
import type { FungibleOptions } from './fungible';
|
|
3
|
+
import { printFungible, defaults as fungibledefaults } from './fungible';
|
|
4
|
+
|
|
5
|
+
export interface WizardContractAPI<Options extends CommonContractOptions> {
|
|
6
|
+
/**
|
|
7
|
+
* Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`.
|
|
8
|
+
*/
|
|
9
|
+
print: (opts?: Options) => string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The default options that are used for `print`.
|
|
13
|
+
*/
|
|
14
|
+
defaults: Required<Options>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AccessControlAPI<Options extends CommonContractOptions> {
|
|
18
|
+
/**
|
|
19
|
+
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
|
|
20
|
+
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
|
|
21
|
+
*/
|
|
22
|
+
isAccessControlRequired: (opts: Partial<Options>) => boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type Fungible = WizardContractAPI<FungibleOptions>; // TODO add AccessControlAPI<FungibleOptions> when access control is implemented, if useful
|
|
26
|
+
|
|
27
|
+
export const fungible: Fungible = {
|
|
28
|
+
print: printFungible,
|
|
29
|
+
defaults: fungibledefaults,
|
|
30
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FungibleOptions } from './fungible';
|
|
2
|
+
import { buildFungible } from './fungible';
|
|
3
|
+
|
|
4
|
+
export interface KindedOptions {
|
|
5
|
+
Fungible: { kind: 'Fungible' } & FungibleOptions;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type GenericOptions = KindedOptions[keyof KindedOptions];
|
|
9
|
+
|
|
10
|
+
export function buildGeneric(opts: GenericOptions) {
|
|
11
|
+
switch (opts.kind) {
|
|
12
|
+
case 'Fungible':
|
|
13
|
+
return buildFungible(opts);
|
|
14
|
+
default: {
|
|
15
|
+
const _: never = opts.kind; // TODO: When there are additional kinds above, change this assignment to just `opts` instead of `opts.kind`
|
|
16
|
+
throw new Error('Unknown ERC');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Argument } from './contract';
|
|
2
|
+
import type { Access } from './set-access-control';
|
|
3
|
+
import type { Info } from './set-info';
|
|
4
|
+
import { defaults as infoDefaults } from './set-info';
|
|
5
|
+
|
|
6
|
+
export const defaults: Required<CommonOptions> = {
|
|
7
|
+
info: infoDefaults,
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export const contractDefaults: Required<CommonContractOptions> = {
|
|
11
|
+
...defaults,
|
|
12
|
+
access: false,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export interface CommonOptions {
|
|
16
|
+
info?: Info;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CommonContractOptions extends CommonOptions {
|
|
20
|
+
access?: Access;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function withCommonDefaults(opts: CommonOptions): Required<CommonOptions> {
|
|
24
|
+
return {
|
|
25
|
+
info: opts.info ?? defaults.info,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function withCommonContractDefaults(opts: CommonContractOptions): Required<CommonContractOptions> {
|
|
30
|
+
return {
|
|
31
|
+
...withCommonDefaults(opts),
|
|
32
|
+
access: opts.access ?? contractDefaults.access,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getSelfArg(): Argument {
|
|
37
|
+
return { name: 'e', type: '&Env' };
|
|
38
|
+
}
|
package/src/contract.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { toIdentifier } from './utils/convert-strings';
|
|
2
|
+
|
|
3
|
+
export interface Contract {
|
|
4
|
+
license: string;
|
|
5
|
+
name: string;
|
|
6
|
+
useClauses: UseClause[];
|
|
7
|
+
constructorCode: string[];
|
|
8
|
+
constructorArgs: Argument[];
|
|
9
|
+
implementedTraits: ImplementedTrait[];
|
|
10
|
+
variables: Variable[];
|
|
11
|
+
errors: Error[];
|
|
12
|
+
ownable: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Error {
|
|
16
|
+
name: string;
|
|
17
|
+
num: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type Value = string | number | bigint | { lit: string } | { note: string; value: Value };
|
|
21
|
+
|
|
22
|
+
export interface UseClause {
|
|
23
|
+
containerPath: string;
|
|
24
|
+
name: string;
|
|
25
|
+
groupable?: boolean;
|
|
26
|
+
alias?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BaseImplementedTrait {
|
|
30
|
+
name: string;
|
|
31
|
+
for: string;
|
|
32
|
+
tags: string[];
|
|
33
|
+
section?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Priority for which trait to print first.
|
|
36
|
+
* Lower numbers are higher priority, undefined is lowest priority.
|
|
37
|
+
*/
|
|
38
|
+
priority?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ImplementedTrait extends BaseImplementedTrait {
|
|
42
|
+
functions: ContractFunction[];
|
|
43
|
+
section?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface BaseFunction {
|
|
47
|
+
name: string;
|
|
48
|
+
args: Argument[];
|
|
49
|
+
code: string[];
|
|
50
|
+
returns?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ContractFunction extends BaseFunction {
|
|
54
|
+
codeBefore?: string[];
|
|
55
|
+
tag?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Variable {
|
|
59
|
+
name: string;
|
|
60
|
+
type: string;
|
|
61
|
+
value: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface Argument {
|
|
65
|
+
name: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class ContractBuilder implements Contract {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
license = 'MIT';
|
|
72
|
+
ownable = false;
|
|
73
|
+
|
|
74
|
+
readonly constructorArgs: Argument[] = [];
|
|
75
|
+
readonly constructorCode: string[] = [];
|
|
76
|
+
|
|
77
|
+
private implementedTraitsMap: Map<string, ImplementedTrait> = new Map();
|
|
78
|
+
private variablesMap: Map<string, Variable> = new Map();
|
|
79
|
+
private useClausesMap: Map<string, UseClause> = new Map();
|
|
80
|
+
private errorsMap: Map<string, Error> = new Map();
|
|
81
|
+
|
|
82
|
+
constructor(name: string) {
|
|
83
|
+
this.name = toIdentifier(name, true);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get implementedTraits(): ImplementedTrait[] {
|
|
87
|
+
return [...this.implementedTraitsMap.values()];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get variables(): Variable[] {
|
|
91
|
+
return [...this.variablesMap.values()];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get useClauses(): UseClause[] {
|
|
95
|
+
return [...this.useClausesMap.values()];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get errors(): Error[] {
|
|
99
|
+
return [...this.errorsMap.values()];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
addError(name: string, num: number): boolean {
|
|
103
|
+
if (this.errorsMap.has(name)) {
|
|
104
|
+
return false;
|
|
105
|
+
} else {
|
|
106
|
+
this.addUseClause('soroban_sdk', 'contracterror');
|
|
107
|
+
this.errorsMap.set(name, { name, num });
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addUseClause(containerPath: string, name: string, options?: { groupable?: boolean; alias?: string }): void {
|
|
113
|
+
// groupable defaults to true
|
|
114
|
+
const groupable = options?.groupable ?? true;
|
|
115
|
+
const alias = options?.alias ?? '';
|
|
116
|
+
const uniqueName = alias.length > 0 ? alias : name;
|
|
117
|
+
const present = this.useClausesMap.has(uniqueName);
|
|
118
|
+
if (!present) {
|
|
119
|
+
this.useClausesMap.set(uniqueName, { containerPath, name, groupable, alias });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addVariable(variable: Variable): boolean {
|
|
124
|
+
if (this.variablesMap.has(variable.name)) {
|
|
125
|
+
return false;
|
|
126
|
+
} else {
|
|
127
|
+
this.variablesMap.set(variable.name, variable);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
addImplementedTrait(baseTrait: BaseImplementedTrait): ImplementedTrait {
|
|
133
|
+
const key = baseTrait.name;
|
|
134
|
+
const existingTrait = this.implementedTraitsMap.get(key);
|
|
135
|
+
if (existingTrait !== undefined) {
|
|
136
|
+
return existingTrait;
|
|
137
|
+
} else {
|
|
138
|
+
const t: ImplementedTrait = {
|
|
139
|
+
name: baseTrait.name,
|
|
140
|
+
for: baseTrait.for,
|
|
141
|
+
tags: [...baseTrait.tags],
|
|
142
|
+
functions: [],
|
|
143
|
+
section: baseTrait.section,
|
|
144
|
+
priority: baseTrait.priority,
|
|
145
|
+
};
|
|
146
|
+
this.implementedTraitsMap.set(key, t);
|
|
147
|
+
return t;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
addFunction(baseTrait: BaseImplementedTrait, fn: BaseFunction): ContractFunction {
|
|
152
|
+
const t = this.addImplementedTrait(baseTrait);
|
|
153
|
+
|
|
154
|
+
const signature = this.getFunctionSignature(fn);
|
|
155
|
+
|
|
156
|
+
// Look for the existing function with the same signature and return it if found
|
|
157
|
+
for (let i = 0; i < t.functions.length; i++) {
|
|
158
|
+
const existingFn = t.functions[i];
|
|
159
|
+
if (existingFn !== undefined && this.getFunctionSignature(existingFn) === signature) {
|
|
160
|
+
return existingFn;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Otherwise, add the function
|
|
165
|
+
const contractFn: ContractFunction = {
|
|
166
|
+
...fn,
|
|
167
|
+
codeBefore: [],
|
|
168
|
+
};
|
|
169
|
+
t.functions.push(contractFn);
|
|
170
|
+
return contractFn;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private getFunctionSignature(fn: BaseFunction): string {
|
|
174
|
+
return [fn.name, '(', ...fn.args.map(a => a.name), ')'].join('');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
addFunctionCodeBefore(baseTrait: BaseImplementedTrait, fn: BaseFunction, codeBefore: string[]): void {
|
|
178
|
+
this.addImplementedTrait(baseTrait);
|
|
179
|
+
const existingFn = this.addFunction(baseTrait, fn);
|
|
180
|
+
existingFn.codeBefore = [...(existingFn.codeBefore ?? []), ...codeBefore];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
addFunctionTag(baseTrait: BaseImplementedTrait, fn: BaseFunction, tag: string): void {
|
|
184
|
+
this.addImplementedTrait(baseTrait);
|
|
185
|
+
const existingFn = this.addFunction(baseTrait, fn);
|
|
186
|
+
existingFn.tag = tag;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
addConstructorArgument(arg: Argument): void {
|
|
190
|
+
for (const existingArg of this.constructorArgs) {
|
|
191
|
+
if (existingArg.name == arg.name) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.constructorArgs.push(arg);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
addConstructorCode(code: string): void {
|
|
199
|
+
this.constructorCode.push(code);
|
|
200
|
+
}
|
|
201
|
+
}
|