@taqueria/plugin-contract-types 0.3.1 → 0.4.0-rc3
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 +125 -0
- package/_readme.eta +128 -0
- package/example/example-usage.ts +2 -2
- package/index.js +113 -150
- package/index.js.map +1 -1
- package/index.ts +32 -33
- package/package.json +53 -53
- package/run.ts +2 -2
- package/src/cli-process.ts +102 -95
- package/src/cli.ts +30 -19
- package/src/generator/common.ts +8 -9
- package/src/generator/contract-name.ts +7 -6
- package/src/generator/contract-parser.ts +324 -322
- package/src/generator/process.ts +70 -50
- package/src/generator/schema-output.ts +48 -47
- package/src/generator/typescript-output.ts +238 -205
- package/src/taquito-contract-type-generator.ts +3 -3
- package/src/type-aliases-file-content.ts +1 -1
- package/src/type-aliases.ts +38 -38
- package/src/type-utils-file-content.ts +1 -1
- package/src/type-utils.ts +23 -25
- package/tasks.ts +48 -51
- package/test/generator.spec.ts +60 -51
- package/tsconfig.json +12 -12
- package/Readme.md +0 -259
package/src/type-utils.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
|
|
2
2
|
|
|
3
|
-
type BaseContractType = { methods: unknown
|
|
3
|
+
type BaseContractType = { methods: unknown; methodsObject: unknown; storage: unknown };
|
|
4
4
|
|
|
5
5
|
type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
6
|
-
[M in keyof TContract['methods']]:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
: never
|
|
6
|
+
[M in keyof TContract['methods']]: TContract['methods'][M] extends (...args: infer A) => unknown
|
|
7
|
+
? (...args: A) => ContractMethod<T>
|
|
8
|
+
: never;
|
|
10
9
|
};
|
|
11
10
|
type ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
12
|
-
[M in keyof TContract['methodsObject']]:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
: never
|
|
11
|
+
[M in keyof TContract['methodsObject']]: TContract['methodsObject'][M] extends (...args: infer A) => unknown
|
|
12
|
+
? (...args: A) => ContractMethodObject<T>
|
|
13
|
+
: never;
|
|
16
14
|
};
|
|
17
15
|
type ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];
|
|
18
16
|
|
|
19
|
-
export type ContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
export type ContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
|
|
18
|
+
ContractProvider,
|
|
19
|
+
ContractMethodsOf<ContractProvider, TContract>,
|
|
20
|
+
ContractMethodsObjectsOf<ContractProvider, TContract>,
|
|
21
|
+
{},
|
|
22
|
+
{},
|
|
23
|
+
ContractStorageOf<TContract>
|
|
24
|
+
>;
|
|
27
25
|
|
|
28
|
-
export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
|
|
27
|
+
Wallet,
|
|
28
|
+
ContractMethodsOf<Wallet, TContract>,
|
|
29
|
+
ContractMethodsObjectsOf<Wallet, TContract>,
|
|
30
|
+
{},
|
|
31
|
+
{},
|
|
32
|
+
ContractStorageOf<TContract>
|
|
33
|
+
>;
|
package/tasks.ts
CHANGED
|
@@ -1,59 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import glob from 'fast-glob'
|
|
3
|
-
import { join } from 'path'
|
|
4
|
-
import { generateContractTypesProcessContractFiles } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
type Opts = SanitizedArgs & Record<string, unknown>;
|
|
12
|
-
|
|
13
|
-
const getContractAbspath = (contractFilename: string, parsedArgs: Opts) =>
|
|
14
|
-
join(parsedArgs.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const generateContractTypes = (parsedArgs: Opts & PluginOpts) => async (contractFilename: string) : Promise<string> => {
|
|
18
|
-
const contractAbspath = getContractAbspath(contractFilename, parsedArgs);
|
|
19
|
-
await generateContractTypesProcessContractFiles({
|
|
20
|
-
inputTzContractDirectory: parsedArgs.artifactsDir,
|
|
21
|
-
inputFiles: [contractAbspath],
|
|
22
|
-
outputTypescriptDirectory: parsedArgs.typescriptDir,
|
|
23
|
-
format: 'tz',
|
|
24
|
-
typeAliasMode: parsedArgs.typeAliasMode ?? 'file',
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return `${contractFilename}: Types generated`;
|
|
1
|
+
import { LikeAPromise, PluginResponse, RequestArgs, TaqError } from '@taqueria/node-sdk/types';
|
|
2
|
+
import glob from 'fast-glob';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { generateContractTypesProcessContractFiles } from './src/cli-process';
|
|
5
|
+
interface Opts extends RequestArgs.ProxyRequestArgs {
|
|
6
|
+
// TODO: Document these
|
|
7
|
+
typescriptDir?: string;
|
|
8
|
+
typeAliasMode?: 'local' | 'file' | 'library' | 'simple';
|
|
9
|
+
contract?: string;
|
|
28
10
|
}
|
|
29
11
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
const getContractAbspath = (contractFilename: string, parsedArgs: Opts) =>
|
|
13
|
+
join(parsedArgs.config.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`);
|
|
14
|
+
|
|
15
|
+
const generateContractTypes = (parsedArgs: Opts) =>
|
|
16
|
+
async (contractFilename: string): Promise<string> => {
|
|
17
|
+
const contractAbspath = getContractAbspath(contractFilename, parsedArgs);
|
|
18
|
+
await generateContractTypesProcessContractFiles({
|
|
19
|
+
inputTzContractDirectory: parsedArgs.config.artifactsDir,
|
|
20
|
+
inputFiles: [contractAbspath],
|
|
21
|
+
outputTypescriptDirectory: parsedArgs.typescriptDir || 'types',
|
|
22
|
+
format: 'tz',
|
|
23
|
+
typeAliasMode: parsedArgs.typeAliasMode ?? 'file',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return `${contractFilename}: Types generated`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const generateContractTypesAll = async (parsedArgs: Opts): Promise<string[]> => {
|
|
30
|
+
const files = await glob('**/*.tz', { cwd: parsedArgs.config.artifactsDir });
|
|
31
|
+
return await Promise.all(files.map(generateContractTypes(parsedArgs)));
|
|
32
|
+
};
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
34
|
+
export const generateTypes = (parsedArgs: Opts): LikeAPromise<PluginResponse, TaqError.t> => {
|
|
35
|
+
parsedArgs.typescriptDir = parsedArgs.typescriptDir || 'types';
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
console.log('generateTypes', {
|
|
38
|
+
typescriptDir: parsedArgs.typescriptDir,
|
|
39
|
+
});
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const p = parsedArgs.contract
|
|
42
|
+
? generateContractTypes(parsedArgs)(parsedArgs.contract)
|
|
43
|
+
: generateContractTypesAll(parsedArgs);
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
45
|
+
return p.then(data => {
|
|
46
|
+
console.log(
|
|
47
|
+
(Array.isArray(data))
|
|
48
|
+
? data.join('\n')
|
|
49
|
+
: data,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
56
53
|
|
|
57
54
|
export const tasks = {
|
|
58
|
-
|
|
59
|
-
}
|
|
55
|
+
generateTypes,
|
|
56
|
+
};
|
package/test/generator.spec.ts
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
|
-
import { generateContractTypesFromMichelsonCode } from '../src/generator/process';
|
|
5
4
|
import { normalizeContractName } from '../src/generator/contract-name';
|
|
5
|
+
import { generateContractTypesFromMichelsonCode } from '../src/generator/process';
|
|
6
6
|
import { TypeAliasData, TypeUtilsData } from '../src/generator/typescript-output';
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
const readFileText = async (filePath: string): Promise<string> => {
|
|
10
|
-
|
|
9
|
+
return fs.readFile(filePath, { encoding: 'utf8' });
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
describe('Generate Example Contracts', () => {
|
|
13
|
+
const typeAliasDataLibrary: TypeAliasData = { mode: 'library', importPath: '@taquito/contract-type-generator' };
|
|
14
|
+
const typeAliasDataSimple: TypeAliasData = { mode: 'simple' };
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
const typeAliasDataSimple: TypeAliasData = { mode: 'simple' };
|
|
17
|
-
|
|
18
|
-
const exampleDir = path.resolve(__dirname, `../example`);
|
|
19
|
-
|
|
20
|
-
const testContractTypeGeneration = async (contractFileName: string, format: 'tz' | 'json', mode: 'library' | 'simple') => {
|
|
21
|
-
const contractRaw = await readFileText(`${exampleDir}/contracts/${contractFileName}.${format}`);
|
|
22
|
-
const expectedTypeFileContent = await readFileText(`${exampleDir}/types${mode === 'simple' ? '-simple' : ''}/${contractFileName}.types.ts`);
|
|
23
|
-
const expectedCodeFileContent = await readFileText(`${exampleDir}/types${mode === 'simple' ? '-simple' : ''}/${contractFileName}.code.ts`);
|
|
24
|
-
const contractName = normalizeContractName(contractFileName);
|
|
25
|
-
const typeAliasData = mode === 'library' ? typeAliasDataLibrary : typeAliasDataSimple;
|
|
26
|
-
const typeUtilsData: TypeUtilsData = { importPath: `./type-utils` };
|
|
27
|
-
const { typescriptCodeOutput: { typesFileContent: actualTypesFileContent, contractCodeFileContent: actualCodeFileContent } } = generateContractTypesFromMichelsonCode(contractRaw, contractName, format, typeAliasData, typeUtilsData);
|
|
28
|
-
expect(actualTypesFileContent.trim()).toEqual(expectedTypeFileContent.trim());
|
|
29
|
-
expect(actualCodeFileContent.trim()).toEqual(expectedCodeFileContent.trim());
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
it('Generate Types 01 - tz library', async () => {
|
|
33
|
-
await testContractTypeGeneration('example-contract-1', 'tz', 'library');
|
|
34
|
-
});
|
|
35
|
-
it('Generate Types 01 - tz simple', async () => {
|
|
36
|
-
await testContractTypeGeneration('example-contract-1', 'tz', 'simple');
|
|
37
|
-
});
|
|
38
|
-
it('Generate Types 02 - tz library', async () => {
|
|
39
|
-
await testContractTypeGeneration('example-contract-2', 'tz', 'library');
|
|
40
|
-
});
|
|
41
|
-
it('Generate Types 02 - tz simple', async () => {
|
|
42
|
-
await testContractTypeGeneration('example-contract-2', 'tz', 'simple');
|
|
43
|
-
});
|
|
16
|
+
const exampleDir = path.resolve(__dirname, `../example`);
|
|
44
17
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
const testContractTypeGeneration = async (
|
|
19
|
+
contractFileName: string,
|
|
20
|
+
format: 'tz' | 'json',
|
|
21
|
+
mode: 'library' | 'simple',
|
|
22
|
+
) => {
|
|
23
|
+
const contractRaw = await readFileText(`${exampleDir}/contracts/${contractFileName}.${format}`);
|
|
24
|
+
const expectedTypeFileContent = await readFileText(
|
|
25
|
+
`${exampleDir}/types${mode === 'simple' ? '-simple' : ''}/${contractFileName}.types.ts`,
|
|
26
|
+
);
|
|
27
|
+
const expectedCodeFileContent = await readFileText(
|
|
28
|
+
`${exampleDir}/types${mode === 'simple' ? '-simple' : ''}/${contractFileName}.code.ts`,
|
|
29
|
+
);
|
|
30
|
+
const contractName = normalizeContractName(contractFileName);
|
|
31
|
+
const typeAliasData = mode === 'library' ? typeAliasDataLibrary : typeAliasDataSimple;
|
|
32
|
+
const typeUtilsData: TypeUtilsData = { importPath: `./type-utils` };
|
|
33
|
+
const {
|
|
34
|
+
typescriptCodeOutput: {
|
|
35
|
+
typesFileContent: actualTypesFileContent,
|
|
36
|
+
contractCodeFileContent: actualCodeFileContent,
|
|
37
|
+
},
|
|
38
|
+
} = generateContractTypesFromMichelsonCode(contractRaw, contractName, format, typeAliasData, typeUtilsData);
|
|
39
|
+
expect(actualTypesFileContent.trim()).toEqual(expectedTypeFileContent.trim());
|
|
40
|
+
expect(actualCodeFileContent.trim()).toEqual(expectedCodeFileContent.trim());
|
|
41
|
+
};
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
it('Generate Types 01 - tz library', async () => {
|
|
44
|
+
await testContractTypeGeneration('example-contract-1', 'tz', 'library');
|
|
45
|
+
});
|
|
46
|
+
it('Generate Types 01 - tz simple', async () => {
|
|
47
|
+
await testContractTypeGeneration('example-contract-1', 'tz', 'simple');
|
|
48
|
+
});
|
|
49
|
+
it('Generate Types 02 - tz library', async () => {
|
|
50
|
+
await testContractTypeGeneration('example-contract-2', 'tz', 'library');
|
|
51
|
+
});
|
|
52
|
+
it('Generate Types 02 - tz simple', async () => {
|
|
53
|
+
await testContractTypeGeneration('example-contract-2', 'tz', 'simple');
|
|
54
|
+
});
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
it('Generate Types 03 - json library', async () => {
|
|
57
|
+
await testContractTypeGeneration('example-contract-3', 'json', 'library');
|
|
58
|
+
});
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
it('Generate Types 04 - newer protocol', async () => {
|
|
61
|
+
await testContractTypeGeneration('example-contract-4', 'tz', 'library');
|
|
62
|
+
});
|
|
63
|
+
it('Generate Types 04 - tz simple', async () => {
|
|
64
|
+
await testContractTypeGeneration('example-contract-4', 'tz', 'simple');
|
|
65
|
+
});
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// });
|
|
67
|
+
// it(`Generate Types - All`, async () => {
|
|
68
|
+
// const allExampleContracts = (await fs.readdir(`${exampleDir}/contracts/`)).filter(f=>f.endsWith('.tz') || f.endsWith('.json'));
|
|
68
69
|
|
|
70
|
+
// for(const f of allExampleContracts){
|
|
71
|
+
// const fRelative = f.replace(exampleDir,'');
|
|
72
|
+
// const m = fRelative.match(/^(.*)\.(tz|json)$/);
|
|
73
|
+
// if(!m){ return; }
|
|
74
|
+
// const [_,filename, ext] = m;
|
|
69
75
|
|
|
76
|
+
// await testContractTypeGeneration(filename, ext as 'tz'|'json', 'simple');
|
|
77
|
+
// }
|
|
78
|
+
// });
|
|
70
79
|
});
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2021",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"outDir": "lib"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/Readme.md
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
This plugin provides a `taq generate types` command which will generate and export TypeScript types from compiled Michelson smart contracts. These generated types then work with your IDE and Taquito, providing type safety and an improved code authoring experience
|
|
2
|
-
|
|
3
|
-
Benefits of using generated types:
|
|
4
|
-
- Static types used to call smart contract methods are checked at compile time, improving code reliability
|
|
5
|
-
- Generated types enable auto-completion and syntax highlighting in your IDE
|
|
6
|
-
- Developing apps with Taquito is faster and more reliable
|
|
7
|
-
- The VS Code Extension provides tooltip hints for parameter types used to call a smart contract method
|
|
8
|
-
- Calling smart contract methods with types is done directly, removing the need for utility methods
|
|
9
|
-
- Simplifies your code and improves readability
|
|
10
|
-
|
|
11
|
-
## Requirements
|
|
12
|
-
|
|
13
|
-
- Node JS v16 or later
|
|
14
|
-
- Taquito v11.2 or later (optional)
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
To install the Contract Types plugin on a Taqueria project, navigate to the project folder and run:
|
|
19
|
-
```shell
|
|
20
|
-
taq install @taqueria/plugin-contract-types
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Configuration
|
|
24
|
-
|
|
25
|
-
This plugin will look for Michelson files according to the `artifactsDir` configured in `./.taq/config.json`. By default, this value is `/artifacts` but can be changed as needed
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
The plugin provides a single command to Taqueria: `taq generate types`
|
|
30
|
-
|
|
31
|
-
This will look for `.tz` files in the `/artifacts` directory and will generate a series of related `.ts` files in the `/types` directory. These files export type definitions for each method which can then be used by Taquito and your IDE
|
|
32
|
-
|
|
33
|
-
### The `generate types` Command
|
|
34
|
-
|
|
35
|
-
#### Syntax
|
|
36
|
-
```shell
|
|
37
|
-
taq generate types [typeOutputDir]
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Parameters
|
|
41
|
-
|
|
42
|
-
| parameter | required | description |
|
|
43
|
-
|:-------------:|:-----------|----------------------------------------------------|
|
|
44
|
-
| typeOutputDir | no | The output directory for the `.ts` files generated |
|
|
45
|
-
|
|
46
|
-
#### CLI Aliases
|
|
47
|
-
|
|
48
|
-
The following aliases are interchangable with `generate types`
|
|
49
|
-
- `gen`
|
|
50
|
-
- `gentypes`
|
|
51
|
-
|
|
52
|
-
#### Options
|
|
53
|
-
|
|
54
|
-
The `generate types` command will accept the following optional parameters:
|
|
55
|
-
|
|
56
|
-
| flag | name | description |
|
|
57
|
-
|:-----:|:--------------|----------------------------------------------|
|
|
58
|
-
| -t | typeAliasMode | Use type aliases in the generated types |
|
|
59
|
-
|
|
60
|
-
## Examples
|
|
61
|
-
|
|
62
|
-
### Example Usage (based on an nft auction contract from open minter sdk)
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
export const exampleContractMethods1 = async () => {
|
|
66
|
-
|
|
67
|
-
const Tezos = new TezosToolkit(`https://YOUR_PREFERRED_RPC_URL`)
|
|
68
|
-
|
|
69
|
-
const contract = await Tezos.contract.at<TestContract>(`tz123`);
|
|
70
|
-
|
|
71
|
-
contract.methods.bid(tas.nat(0));
|
|
72
|
-
contract.methods.configure(
|
|
73
|
-
/*opening_price:*/ tas.mutez(10),
|
|
74
|
-
/*min_raise_percent:*/ tas.nat(10),
|
|
75
|
-
/*min_raise:*/ tas.mutez(10),
|
|
76
|
-
/*round_time:*/ tas.nat(10),
|
|
77
|
-
/*extend_time:*/ tas.nat(10),
|
|
78
|
-
/*asset:*/ [{
|
|
79
|
-
fa2_address: tas.address(`tz123`),
|
|
80
|
-
fa2_batch: [{
|
|
81
|
-
amount: tas.nat(100),
|
|
82
|
-
token_id: tas.nat(`100000000000000`),
|
|
83
|
-
}],
|
|
84
|
-
}],
|
|
85
|
-
/*start_time:*/ tas.timestamp(new Date()),
|
|
86
|
-
/*end_time:*/ tas.timestamp(`2020-01-01`),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
// methodsObject
|
|
90
|
-
contract.methodsObject.bid(tas.nat(0));
|
|
91
|
-
contract.methodsObject.configure({
|
|
92
|
-
asset: [{
|
|
93
|
-
fa2_address: tas.address(`tz123`),
|
|
94
|
-
fa2_batch: [{
|
|
95
|
-
amount: tas.nat(100),
|
|
96
|
-
token_id: tas.nat(`100000000000000`),
|
|
97
|
-
}],
|
|
98
|
-
}],
|
|
99
|
-
start_time: tas.timestamp(new Date()),
|
|
100
|
-
end_time: tas.timestamp(`2020-01-01`),
|
|
101
|
-
extend_time: tas.nat(10),
|
|
102
|
-
min_raise: tas.mutez(10),
|
|
103
|
-
min_raise_percent: tas.nat(10),
|
|
104
|
-
opening_price: tas.mutez(10),
|
|
105
|
-
round_time: tas.nat(10),
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Example typegen task
|
|
112
|
-
|
|
113
|
-
```console
|
|
114
|
-
$ taqueria typegen --typescriptDir ./types
|
|
115
|
-
generateTypes
|
|
116
|
-
{
|
|
117
|
-
"typescriptDir": "./types"
|
|
118
|
-
}
|
|
119
|
-
Generating Types: /home/rick/projects/crypto/taqueria/example/artifacts => /home/rick/projects/crypto/taqueria/example/types
|
|
120
|
-
Contracts Found:
|
|
121
|
-
- /home/rick/projects/crypto/taqueria/example/artifacts/example-contract-1.tz
|
|
122
|
-
Processing /example-contract-1.tz...example-contract-1.tz: Types generated
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
### Example type output
|
|
127
|
-
|
|
128
|
-
```ts
|
|
129
|
-
type Storage = {
|
|
130
|
-
pauseable_admin?: {
|
|
131
|
-
admin: address;
|
|
132
|
-
paused: boolean;
|
|
133
|
-
pending_admin?: address;
|
|
134
|
-
};
|
|
135
|
-
current_id: nat;
|
|
136
|
-
max_auction_time: nat;
|
|
137
|
-
max_config_to_start_time: nat;
|
|
138
|
-
auctions: BigMap<nat, {
|
|
139
|
-
seller: address;
|
|
140
|
-
current_bid: mutez;
|
|
141
|
-
start_time: timestamp;
|
|
142
|
-
last_bid_time: timestamp;
|
|
143
|
-
round_time: int;
|
|
144
|
-
extend_time: int;
|
|
145
|
-
asset: Array<{
|
|
146
|
-
fa2_address: address;
|
|
147
|
-
fa2_batch: Array<{
|
|
148
|
-
token_id: nat;
|
|
149
|
-
amount: nat;
|
|
150
|
-
}>;
|
|
151
|
-
}>;
|
|
152
|
-
min_raise_percent: nat;
|
|
153
|
-
min_raise: mutez;
|
|
154
|
-
end_time: timestamp;
|
|
155
|
-
highest_bidder: address;
|
|
156
|
-
}>;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
type Methods = {
|
|
160
|
-
confirm_admin: () => Promise<void>;
|
|
161
|
-
pause: (param: boolean) => Promise<void>;
|
|
162
|
-
set_admin: (param: address) => Promise<void>;
|
|
163
|
-
bid: (param: nat) => Promise<void>;
|
|
164
|
-
cancel: (param: nat) => Promise<void>;
|
|
165
|
-
configure: (
|
|
166
|
-
opening_price: mutez,
|
|
167
|
-
min_raise_percent: nat,
|
|
168
|
-
min_raise: mutez,
|
|
169
|
-
round_time: nat,
|
|
170
|
-
extend_time: nat,
|
|
171
|
-
asset: Array<{
|
|
172
|
-
fa2_address: address;
|
|
173
|
-
fa2_batch: Array<{
|
|
174
|
-
token_id: nat;
|
|
175
|
-
amount: nat;
|
|
176
|
-
}>;
|
|
177
|
-
}>,
|
|
178
|
-
start_time: timestamp,
|
|
179
|
-
end_time: timestamp,
|
|
180
|
-
) => Promise<void>;
|
|
181
|
-
resolve: (param: nat) => Promise<void>;
|
|
182
|
-
};
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
## Taquito library changes
|
|
187
|
-
|
|
188
|
-
See [example-usage.ts](example/example-usage.ts) for full example
|
|
189
|
-
|
|
190
|
-
### Before
|
|
191
|
-
|
|
192
|
-
Using taquito with the generated contract types:
|
|
193
|
-
|
|
194
|
-
The at method can be called providing a type with a utility method that can be provided:
|
|
195
|
-
```ts
|
|
196
|
-
const contract = await Tezos.contract.at(`tz123`, contractAbstractionComposer<TestContractType>());
|
|
197
|
-
|
|
198
|
-
// methods can now use typed parameters
|
|
199
|
-
// methodsObject will be able to use type parameters
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
This can work the same with a wallet
|
|
203
|
-
```ts
|
|
204
|
-
const contract = await Tezos.wallet.at(`tz123`, walletAbstractionComposer<TestContractType>());
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Alternatively, this can be done with a cast:
|
|
208
|
-
```ts
|
|
209
|
-
const contract = await Tezos.contract.at(`tz123`) as ContractProviderFromContractType<TestContractType>;
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
The originate contract does not have any way to provide a type, so this requires a cast:
|
|
214
|
-
```ts
|
|
215
|
-
const originationResult = await Tezos.contract.originate({...});
|
|
216
|
-
const contract = await originationResult.contract(5) as ContractProviderFromContractType<TestContractType2>;
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
For accessing storage, there is no way to pass the type through the contract class,
|
|
221
|
-
so it requires providing the type again:
|
|
222
|
-
```ts
|
|
223
|
-
const contract = await Tezos.contract.at(`tz123`) as ContractProviderFromContractType<TestContractType>;
|
|
224
|
-
const storage = await contract.storage<StorageFromContractType<TestContractType>>();
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
### After
|
|
229
|
-
|
|
230
|
-
Extending ContractAbstraction with additional generic types:
|
|
231
|
-
|
|
232
|
-
The at method can be called with the contract type provided:
|
|
233
|
-
```ts
|
|
234
|
-
const contract = await Tezos.contract.at<TestContract>(`tz123`);
|
|
235
|
-
|
|
236
|
-
// methods can now use typed parameters
|
|
237
|
-
// methodsObject will be able to use type parameters
|
|
238
|
-
// storage will be able to use type parameters
|
|
239
|
-
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
This can work the same with a wallet
|
|
243
|
-
```ts
|
|
244
|
-
const contract = await Tezos.wallet.at<TestWalletContract>(`tz123`);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
The originate contract now accepts a type:
|
|
248
|
-
```ts
|
|
249
|
-
const originationResult = await Tezos.contract.originate({...});
|
|
250
|
-
const contract = await originationResult.contract<TestContract2>(5);
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
The contract type now also provides the default storage type:
|
|
255
|
-
```ts
|
|
256
|
-
const contract = await Tezos.contract.at<TestContract>(`tz123`);
|
|
257
|
-
const storage = await contract.storage();
|
|
258
|
-
```
|
|
259
|
-
|