@alephium/web3 0.0.3

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.
Files changed (59) hide show
  1. package/.gitattributes +1 -0
  2. package/LICENSE +165 -0
  3. package/README.md +136 -0
  4. package/contracts/add.ral +12 -0
  5. package/contracts/greeter-main.ral +8 -0
  6. package/contracts/greeter.ral +5 -0
  7. package/contracts/main.ral +8 -0
  8. package/contracts/sub.ral +9 -0
  9. package/dev/user.conf +24 -0
  10. package/dist/alephium-web3.min.js +3 -0
  11. package/dist/alephium-web3.min.js.LICENSE.txt +27 -0
  12. package/dist/alephium-web3.min.js.map +1 -0
  13. package/dist/api/api-alephium.d.ts +1292 -0
  14. package/dist/api/api-alephium.js +761 -0
  15. package/dist/api/api-explorer.d.ts +350 -0
  16. package/dist/api/api-explorer.js +297 -0
  17. package/dist/cli/create-project.d.ts +2 -0
  18. package/dist/cli/create-project.js +87 -0
  19. package/dist/lib/address.d.ts +1 -0
  20. package/dist/lib/address.js +42 -0
  21. package/dist/lib/bs58.d.ts +4 -0
  22. package/dist/lib/bs58.js +26 -0
  23. package/dist/lib/clique.d.ts +23 -0
  24. package/dist/lib/clique.js +149 -0
  25. package/dist/lib/constants.d.ts +2 -0
  26. package/dist/lib/constants.js +22 -0
  27. package/dist/lib/contract.d.ts +152 -0
  28. package/dist/lib/contract.js +711 -0
  29. package/dist/lib/djb2.d.ts +1 -0
  30. package/dist/lib/djb2.js +27 -0
  31. package/dist/lib/explorer.d.ts +8 -0
  32. package/dist/lib/explorer.js +46 -0
  33. package/dist/lib/index.d.ts +12 -0
  34. package/dist/lib/index.js +60 -0
  35. package/dist/lib/node.d.ts +10 -0
  36. package/dist/lib/node.js +64 -0
  37. package/dist/lib/numbers.d.ts +7 -0
  38. package/dist/lib/numbers.js +128 -0
  39. package/dist/lib/password-crypto.d.ts +2 -0
  40. package/dist/lib/password-crypto.js +68 -0
  41. package/dist/lib/signer.d.ts +17 -0
  42. package/dist/lib/signer.js +70 -0
  43. package/dist/lib/storage-browser.d.ts +9 -0
  44. package/dist/lib/storage-browser.js +52 -0
  45. package/dist/lib/storage-node.d.ts +9 -0
  46. package/dist/lib/storage-node.js +65 -0
  47. package/dist/lib/utils.d.ts +11 -0
  48. package/dist/lib/utils.js +135 -0
  49. package/dist/lib/wallet.d.ts +30 -0
  50. package/dist/lib/wallet.js +142 -0
  51. package/gitignore +9 -0
  52. package/package.json +113 -0
  53. package/scripts/check-versions.js +45 -0
  54. package/scripts/rename-gitignore.js +24 -0
  55. package/scripts/start-devnet.js +141 -0
  56. package/scripts/stop-devnet.js +32 -0
  57. package/templates/README.md +34 -0
  58. package/templates/package.json +29 -0
  59. package/webpack.config.js +57 -0
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ Copyright 2018 - 2022 The Alephium Authors
5
+ This file is part of the alephium project.
6
+
7
+ The library is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Lesser General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ The library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public License
18
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ const fs_extra_1 = __importDefault(require("fs-extra"));
25
+ const process_1 = __importDefault(require("process"));
26
+ const path_1 = __importDefault(require("path"));
27
+ const find_up_1 = __importDefault(require("find-up"));
28
+ const chalk_1 = __importDefault(require("chalk"));
29
+ function getPackageRoot() {
30
+ const packageJsonPath = find_up_1.default.sync('package.json', { cwd: path_1.default.dirname(__filename) });
31
+ if (packageJsonPath) {
32
+ return path_1.default.dirname(packageJsonPath);
33
+ }
34
+ else {
35
+ throw new Error('Cannot find `package.json`');
36
+ }
37
+ }
38
+ const packageRoot = getPackageRoot();
39
+ const projectParent = process_1.default.cwd();
40
+ const projectName = process_1.default.argv[2];
41
+ if (!projectName) {
42
+ console.log('Please provide a project name');
43
+ console.log(` ${chalk_1.default.cyan('alephium')} ${chalk_1.default.green('<project-name>')}`);
44
+ console.log();
45
+ console.log('For example:');
46
+ console.log(` ${chalk_1.default.cyan('alephium')} ${chalk_1.default.green('my-alephium-dapp')}`);
47
+ console.log();
48
+ process_1.default.exit(1);
49
+ }
50
+ const projectRoot = path_1.default.join(projectParent, projectName);
51
+ if (fs_extra_1.default.existsSync(projectRoot)) {
52
+ console.log(`Project ${projectName} already exists. Try a different name.`);
53
+ console.log();
54
+ process_1.default.exit(1);
55
+ }
56
+ console.log('Copying files');
57
+ console.log(` from ${packageRoot}`);
58
+ console.log(` to ${projectRoot}`);
59
+ console.log('...');
60
+ function copy(dir, files) {
61
+ const packageDevDir = path_1.default.join(packageRoot, dir);
62
+ const projectDevDir = path_1.default.join(projectRoot, dir);
63
+ fs_extra_1.default.mkdirSync(projectDevDir);
64
+ for (const file of files) {
65
+ fs_extra_1.default.copyFileSync(path_1.default.join(packageDevDir, file), path_1.default.join(projectDevDir, file));
66
+ }
67
+ }
68
+ copy('', ['.gitattributes']);
69
+ copy('dev', ['user.conf']);
70
+ copy('scripts', ['start-devnet.js', 'stop-devnet.js']);
71
+ copy('contracts', ['greeter.ral', 'greeter-main.ral']);
72
+ fs_extra_1.default.mkdirSync(path_1.default.join(projectRoot, 'src'));
73
+ fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'gitignore'), path_1.default.join(projectRoot, '.gitignore'));
74
+ fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates', 'package.json'), path_1.default.join(projectRoot, 'package.json'));
75
+ fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates', 'tsconfig.json'), path_1.default.join(projectRoot, 'tsconfig.json'));
76
+ fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates', 'README.md'), path_1.default.join(projectRoot, 'README.md'));
77
+ fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates', 'greeter.ts'), path_1.default.join(projectRoot, 'src', 'greeter.ts'));
78
+ console.log('✅ Done.');
79
+ console.log();
80
+ console.log('✨ Project is initialized!');
81
+ console.log();
82
+ console.log('Next steps:');
83
+ console.log(` ${chalk_1.default.cyan(`cd ${projectName}`)}`);
84
+ console.log(` ${chalk_1.default.cyan('npm install')}`);
85
+ console.log(` ${chalk_1.default.cyan('npm run compile')}`);
86
+ console.log(` ${chalk_1.default.cyan('npm run devnet:start')}`);
87
+ console.log(` ${chalk_1.default.cyan('node dist/greeter.js')}`);
@@ -0,0 +1 @@
1
+ export declare function addressToGroup(address: string, totalNumberOfGroups: number): number;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.addressToGroup = void 0;
24
+ const bs58_1 = __importDefault(require("./bs58"));
25
+ const djb2_1 = __importDefault(require("../lib/djb2"));
26
+ function addressToGroup(address, totalNumberOfGroups) {
27
+ const bytes = bs58_1.default.decode(address).slice(1);
28
+ const value = (0, djb2_1.default)(bytes) | 1;
29
+ const hash = toPosInt(xorByte(value));
30
+ const group = hash % totalNumberOfGroups;
31
+ return group;
32
+ }
33
+ exports.addressToGroup = addressToGroup;
34
+ function xorByte(value) {
35
+ const byte0 = value >> 24;
36
+ const byte1 = value >> 16;
37
+ const byte2 = value >> 8;
38
+ return byte0 ^ byte1 ^ byte2 ^ value;
39
+ }
40
+ function toPosInt(byte) {
41
+ return byte & 0xff;
42
+ }
@@ -0,0 +1,4 @@
1
+ /** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
2
+ import basex from 'base-x';
3
+ declare const _default: basex.BaseConverter;
4
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ /** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
24
+ const base_x_1 = __importDefault(require("base-x"));
25
+ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
26
+ exports.default = (0, base_x_1.default)(ALPHABET);
@@ -0,0 +1,23 @@
1
+ import * as api from '../api/api-alephium';
2
+ import { Api, SelfClique } from '../api/api-alephium';
3
+ import { NodeClient } from './node';
4
+ /**
5
+ * Clique Client
6
+ */
7
+ export declare class CliqueClient extends Api<null> {
8
+ clique: SelfClique;
9
+ clients: NodeClient[];
10
+ init(isMultiNodesClique: boolean): Promise<void>;
11
+ static convert<T>(response: api.HttpResponse<T, {
12
+ detail: string;
13
+ }>): T;
14
+ selfClique(): Promise<api.HttpResponse<api.SelfClique, api.BadRequest | api.InternalServerError | api.NotFound | api.ServiceUnavailable | api.Unauthorized>>;
15
+ getClientIndex(address: string): number;
16
+ getBalance(address: string): Promise<api.HttpResponse<api.Balance, api.BadRequest | api.InternalServerError | api.NotFound | api.ServiceUnavailable | api.Unauthorized>>;
17
+ getWebSocket(node_i: number): WebSocket | undefined;
18
+ transactionCreate(fromAddress: string, fromPublicKey: string, toAddress: string, amount: string, lockTime?: number, gas?: number, gasPrice?: string): Promise<api.HttpResponse<api.BuildTransactionResult, api.BadRequest | api.InternalServerError | api.NotFound | api.ServiceUnavailable | api.Unauthorized>>;
19
+ transactionConsolidateUTXOs(fromPublicKey: string, fromAddress: string, toAddress: string): Promise<api.HttpResponse<api.BuildSweepAddressTransactionsResult, api.BadRequest | api.InternalServerError | api.NotFound | api.ServiceUnavailable | api.Unauthorized>>;
20
+ transactionSend(fromAddress: string, tx: string, signature: string): Promise<api.HttpResponse<api.TxResult, api.BadRequest | api.InternalServerError | api.NotFound | api.ServiceUnavailable | api.Unauthorized>>;
21
+ transactionSign(txHash: string, privateKey: string): string;
22
+ transactionVerifySignature(txHash: string, publicKey: string, signature: string): boolean;
23
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28
+ }) : function(o, v) {
29
+ o["default"] = v;
30
+ });
31
+ var __importStar = (this && this.__importStar) || function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
+ return new (P || (P = Promise))(function (resolve, reject) {
41
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
42
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
43
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
44
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45
+ });
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.CliqueClient = void 0;
49
+ const elliptic_1 = require("elliptic");
50
+ const api_alephium_1 = require("../api/api-alephium");
51
+ const node_1 = require("./node");
52
+ const utils = __importStar(require("./utils"));
53
+ const ec = new elliptic_1.ec('secp256k1');
54
+ /**
55
+ * Clique Client
56
+ */
57
+ class CliqueClient extends api_alephium_1.Api {
58
+ init(isMultiNodesClique) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ this.clients = [];
61
+ const res = yield this.selfClique();
62
+ if (isMultiNodesClique) {
63
+ this.clique = res.data;
64
+ if (this.clique.nodes) {
65
+ for (const node of this.clique.nodes) {
66
+ const client = new node_1.NodeClient({
67
+ baseUrl: `http://${node.address}:${node.restPort}`
68
+ });
69
+ this.clients.push(client);
70
+ }
71
+ }
72
+ }
73
+ else {
74
+ const client = new node_1.NodeClient({
75
+ baseUrl: this.baseUrl
76
+ });
77
+ this.clients.push(client);
78
+ }
79
+ });
80
+ }
81
+ static convert(response) {
82
+ if (response.error) {
83
+ console.log(response.error.detail);
84
+ throw new Error(response.error.detail);
85
+ }
86
+ else {
87
+ return response.data;
88
+ }
89
+ }
90
+ selfClique() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const res = yield this.infos.getInfosSelfClique();
93
+ if (res.error)
94
+ throw new Error(res.error.detail);
95
+ return res;
96
+ });
97
+ }
98
+ getClientIndex(address) {
99
+ if (this.clients.length === 0)
100
+ throw new Error('No nodes in the clique');
101
+ const group = utils.groupOfAddress(address);
102
+ return group % this.clients.length;
103
+ }
104
+ getBalance(address) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const clientIndex = this.getClientIndex(address);
107
+ return yield this.clients[clientIndex].getBalance(address);
108
+ });
109
+ }
110
+ getWebSocket(node_i) {
111
+ if (this.clique.nodes) {
112
+ const node = this.clique.nodes[node_i];
113
+ return new WebSocket('ws://' + node.address + ':' + node.wsPort + '/events');
114
+ }
115
+ }
116
+ transactionCreate(fromAddress, fromPublicKey, toAddress, amount, lockTime, gas, gasPrice) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const clientIndex = this.getClientIndex(fromAddress);
119
+ return yield this.clients[clientIndex].transactionCreate(fromPublicKey, toAddress, amount, lockTime, gas, gasPrice);
120
+ });
121
+ }
122
+ transactionConsolidateUTXOs(fromPublicKey, fromAddress, toAddress) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const clientIndex = this.getClientIndex(fromAddress);
125
+ return yield this.clients[clientIndex].transactionConsolidateUTXOs(fromPublicKey, toAddress);
126
+ });
127
+ }
128
+ transactionSend(fromAddress, tx, signature) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const clientIndex = this.getClientIndex(fromAddress);
131
+ return yield this.clients[clientIndex].transactionSend(tx, signature);
132
+ });
133
+ }
134
+ transactionSign(txHash, privateKey) {
135
+ const keyPair = ec.keyFromPrivate(privateKey);
136
+ const signature = keyPair.sign(txHash);
137
+ return utils.signatureEncode(ec, signature);
138
+ }
139
+ transactionVerifySignature(txHash, publicKey, signature) {
140
+ try {
141
+ const key = ec.keyFromPublic(publicKey, 'hex');
142
+ return key.verify(txHash, utils.signatureDecode(ec, signature));
143
+ }
144
+ catch (error) {
145
+ return false;
146
+ }
147
+ }
148
+ }
149
+ exports.CliqueClient = CliqueClient;
@@ -0,0 +1,2 @@
1
+ export declare const TOTAL_NUMBER_OF_GROUPS = 4;
2
+ export declare const MIN_UTXO_SET_AMOUNT: bigint;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
21
+ exports.TOTAL_NUMBER_OF_GROUPS = 4;
22
+ exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
@@ -0,0 +1,152 @@
1
+ import { CliqueClient } from './clique';
2
+ import * as api from '../api/api-alephium';
3
+ import { Signer } from './signer';
4
+ export declare abstract class Common {
5
+ readonly fileName: string;
6
+ readonly sourceCodeSha256: string;
7
+ readonly bytecode: string;
8
+ readonly codeHash: string;
9
+ readonly functions: api.FunctionSig[];
10
+ static readonly importRegex: RegExp;
11
+ static readonly contractRegex: RegExp;
12
+ static readonly scriptRegex: RegExp;
13
+ static readonly variableRegex: RegExp;
14
+ constructor(fileName: string, sourceCodeSha256: string, bytecode: string, codeHash: string, functions: api.FunctionSig[]);
15
+ protected static _contractPath(fileName: string): string;
16
+ protected static _artifactPath(fileName: string): string;
17
+ protected static _artifactsFolder(): string;
18
+ static handleImports(contractStr: string, importsCache: string[]): Promise<string>;
19
+ protected static _replaceVariables(contractStr: string, variables?: any): string;
20
+ protected static _loadContractStr(fileName: string, importsCache: string[], validate: (fileName: string) => void): Promise<string>;
21
+ static checkFileNameExtension(fileName: string): void;
22
+ protected static _from<T extends {
23
+ sourceCodeSha256: string;
24
+ }>(client: CliqueClient, fileName: string, loadContractStr: (fileName: string, importsCache: string[]) => Promise<string>, loadContract: (fileName: string) => Promise<T>, __from: (client: CliqueClient, fileName: string, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
25
+ static load(fileName: string): Promise<Contract | Script>;
26
+ protected _saveToFile(): Promise<void>;
27
+ }
28
+ export declare class Contract extends Common {
29
+ readonly fields: api.FieldsSig;
30
+ readonly events: api.EventSig[];
31
+ private _contractAddresses;
32
+ constructor(fileName: string, sourceCodeSha256: string, bytecode: string, codeHash: string, fields: api.FieldsSig, functions: api.FunctionSig[], events: api.EventSig[]);
33
+ static checkCodeType(fileName: string, contractStr: string): void;
34
+ static loadContractStr(fileName: string, importsCache: string[], variables?: any): Promise<string>;
35
+ static from(client: CliqueClient, fileName: string, variables?: any): Promise<Contract>;
36
+ private static __from;
37
+ static loadContract(fileName: string): Promise<Contract>;
38
+ toString(): string;
39
+ toState(fields: Val[], asset: Asset, address: string): ContractState;
40
+ static randomAddress(): string;
41
+ private _randomAddressWithCache;
42
+ test(client: CliqueClient, funcName: string, params: TestContractParams): Promise<TestContractResult>;
43
+ toApiFields(fields?: Val[]): api.Val[];
44
+ toApiArgs(funcName: string, args?: Val[]): api.Val[];
45
+ getMethodIndex(funcName: string): number;
46
+ toApiContractState(state: ContractState): api.ContractState;
47
+ toApiContractStates(states?: ContractState[]): api.ContractState[] | undefined;
48
+ toTestContract(funcName: string, params: TestContractParams): api.TestContract;
49
+ static getContract(codeHash: string): Promise<Contract>;
50
+ static getFieldTypes(codeHash: string): Promise<string[]>;
51
+ fromApiContractState(state: api.ContractState): Promise<ContractState>;
52
+ static fromApiEvent(event: api.Event, fileName: string): Promise<ContractEvent>;
53
+ fromTestContractResult(methodIndex: number, result: api.TestContractResult): Promise<TestContractResult>;
54
+ transactionForDeployment(signer: Signer, initialFields?: Val[], issueTokenAmount?: string): Promise<DeployContractTransaction>;
55
+ }
56
+ export declare class Script extends Common {
57
+ constructor(fileName: string, sourceCodeSha256: string, bytecode: string, codeHash: string, functions: api.FunctionSig[]);
58
+ static checkCodeType(fileName: string, contractStr: string): void;
59
+ static loadContractStr(fileName: string, importsCache: string[], variables?: any): Promise<string>;
60
+ static from(client: CliqueClient, fileName: string, variables?: any): Promise<Script>;
61
+ private static __from;
62
+ static loadContract(fileName: string): Promise<Script>;
63
+ toString(): string;
64
+ transactionForDeployment(signer: Signer, params?: BuildScriptTx): Promise<BuildScriptTxResult>;
65
+ }
66
+ export declare type Number256 = number | bigint;
67
+ export declare type Val = Number256 | boolean | string | Val[];
68
+ export declare function extractArray(tpe: string, v: Val): api.Val;
69
+ export interface Asset {
70
+ alphAmount: Number256;
71
+ tokens?: Token[];
72
+ }
73
+ export interface Token {
74
+ id: string;
75
+ amount: Number256;
76
+ }
77
+ export interface InputAsset {
78
+ address: string;
79
+ asset: Asset;
80
+ }
81
+ export interface ContractState {
82
+ fileName: string;
83
+ address: string;
84
+ bytecode: string;
85
+ codeHash: string;
86
+ fields: Val[];
87
+ fieldTypes: string[];
88
+ asset: Asset;
89
+ }
90
+ export interface TestContractParams {
91
+ group?: number;
92
+ address?: string;
93
+ initialFields?: Val[];
94
+ initialAsset?: Asset;
95
+ testMethodIndex?: number;
96
+ testArgs?: Val[];
97
+ existingContracts?: ContractState[];
98
+ inputAssets?: InputAsset[];
99
+ }
100
+ declare type Event = ContractEvent | TxScriptEvent;
101
+ export interface ContractEvent {
102
+ blockHash: string;
103
+ contractAddress: string;
104
+ txId: string;
105
+ name: string;
106
+ fields: Val[];
107
+ }
108
+ export interface TxScriptEvent {
109
+ blockHash: string;
110
+ txId: string;
111
+ name: string;
112
+ fields: Val[];
113
+ }
114
+ export interface TestContractResult {
115
+ returns: Val[];
116
+ gasUsed: number;
117
+ contracts: ContractState[];
118
+ txOutputs: Output[];
119
+ events: Event[];
120
+ }
121
+ export declare type Output = AssetOutput | ContractOutput;
122
+ export interface AssetOutput extends Asset {
123
+ type: string;
124
+ address: string;
125
+ lockTime: number;
126
+ additionalData: string;
127
+ }
128
+ export interface ContractOutput {
129
+ type: string;
130
+ address: string;
131
+ alphAmount: Number256;
132
+ tokens: Token[];
133
+ }
134
+ export interface DeployContractTransaction {
135
+ group: number;
136
+ unsignedTx: string;
137
+ txId: string;
138
+ contractAddress: string;
139
+ }
140
+ export interface BuildScriptTx {
141
+ alphAmount?: Number256;
142
+ tokens?: Token[];
143
+ gas?: number;
144
+ gasPrice?: Number256;
145
+ utxosLimit?: number;
146
+ }
147
+ export interface BuildScriptTxResult {
148
+ unsignedTx: string;
149
+ txId: string;
150
+ group: number;
151
+ }
152
+ export {};