1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const Constant_1 = require("./Constant");
|
13 | const AsiLinkProvider_1 = require("./providers/AsiLinkProvider");
|
14 | const ChainRpcProvider_1 = require("./providers/ChainRpcProvider");
|
15 | const Compiler_1 = require("./contract/Compiler");
|
16 | const FileManager_1 = require("./contract/FileManager");
|
17 | let Module = require('./compiler/asimov.js');
|
18 |
|
19 |
|
20 |
|
21 | const DefaultRemoteCompiler = 'https://cdn.asimov.work/asimov.js';
|
22 |
|
23 |
|
24 |
|
25 | class Setting {
|
26 | constructor(config) {
|
27 | if (config) {
|
28 | Setting._instance.init(config);
|
29 | }
|
30 | return Setting._instance;
|
31 | }
|
32 | |
33 |
|
34 |
|
35 | static getInstance() {
|
36 | return this._instance;
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 | init(config = {}) {
|
43 | return __awaiter(this, void 0, void 0, function* () {
|
44 | this.setPrivateKey(config.privateKey);
|
45 | if (config.compiler) {
|
46 | this.setSolidityCompiler(config.compiler);
|
47 | }
|
48 | if (config.bundleId) {
|
49 | this.setAsiLink(config.bundleId);
|
50 | }
|
51 | if (config.url) {
|
52 | this.setRpcServer(config.url);
|
53 | }
|
54 | if (config.fee) {
|
55 | this.setTransactionFee(config.fee.amount, config.fee.asset);
|
56 | }
|
57 | if (config.remoteCompiler) {
|
58 | Module = yield FileManager_1.FileManager.importRemoteScript(config.remoteCompiler);
|
59 | this.setSolidityCompiler(new Compiler_1.Compiler(Module));
|
60 | }
|
61 | else if (!this.compiler) {
|
62 | if (!Module) {
|
63 | Module = yield FileManager_1.FileManager.importRemoteScript(DefaultRemoteCompiler);
|
64 | }
|
65 | this.setSolidityCompiler(new Compiler_1.Compiler(Module));
|
66 | }
|
67 | this.asiLinkProvider = new AsiLinkProvider_1.AsiLinkProvider();
|
68 | });
|
69 | }
|
70 | |
71 |
|
72 |
|
73 |
|
74 | setSolidityCompiler(compiler) {
|
75 | this.compiler = compiler;
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 | setPrivateKey(privateKey) {
|
82 | this.privateKey = privateKey;
|
83 | }
|
84 | |
85 |
|
86 |
|
87 |
|
88 | setAsiLink(bundleId) {
|
89 | this.bundleId = bundleId;
|
90 | }
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 | setTransactionFee(assetValue = 0, assetType = Constant_1.DefaultAsset) {
|
97 | let fee = {
|
98 | amount: assetValue,
|
99 | asset: assetType
|
100 | };
|
101 | this.fee = fee;
|
102 | }
|
103 | |
104 |
|
105 |
|
106 |
|
107 | setRpcServer(url) {
|
108 | this.chainRpcProvider = new ChainRpcProvider_1.ChainRpcProvider({
|
109 | baseURL: url
|
110 | });
|
111 | }
|
112 | |
113 |
|
114 |
|
115 | static GetPrivateKey() {
|
116 | return Setting.getInstance().privateKey;
|
117 | }
|
118 | }
|
119 | exports.Setting = Setting;
|
120 | Setting._instance = new Setting();
|
121 |
|
\ | No newline at end of file |