@prosopo/env 1.0.2 → 2.0.1
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/dist/cjs/env.cjs +35 -71
- package/dist/cjs/mockenv.cjs +1 -1
- package/dist/env.d.ts +7 -18
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +32 -67
- package/dist/env.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mockenv.d.ts +3 -3
- package/dist/mockenv.d.ts.map +1 -1
- package/dist/mockenv.js +2 -2
- package/dist/mockenv.js.map +1 -1
- package/dist/provider.d.ts +2 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +1 -1
- package/dist/provider.js.map +1 -1
- package/package.json +46 -52
- package/vite.cjs.config.ts +3 -3
package/dist/cjs/env.cjs
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Api = require("@polkadot/api/promise/Api");
|
|
4
|
-
const database = require("@prosopo/database");
|
|
5
3
|
const keyring = require("@polkadot/keyring");
|
|
6
4
|
const common = require("@prosopo/common");
|
|
7
|
-
const
|
|
8
|
-
const ws = require("@polkadot/rpc-provider/ws");
|
|
9
|
-
const contractInfo = require("@prosopo/captcha-contract/contract-info");
|
|
5
|
+
const database = require("@prosopo/database");
|
|
10
6
|
const util = require("@prosopo/util");
|
|
11
|
-
const address = require("@polkadot/util-crypto/address");
|
|
12
7
|
class Environment {
|
|
13
8
|
constructor(config, pair) {
|
|
14
9
|
this.config = config;
|
|
15
10
|
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
16
11
|
this.defaultNetwork = this.config.defaultNetwork;
|
|
17
12
|
this.pair = pair;
|
|
18
|
-
this.logger = common.getLogger(this.config.logLevel,
|
|
19
|
-
if (this.config.defaultNetwork && Object.prototype.hasOwnProperty.call(
|
|
13
|
+
this.logger = common.getLogger(this.config.logLevel, "ProsopoEnvironment");
|
|
14
|
+
if (this.config.defaultNetwork && Object.prototype.hasOwnProperty.call(
|
|
15
|
+
this.config.networks,
|
|
16
|
+
this.config.defaultNetwork
|
|
17
|
+
) && this.config.networks && this.config.networks[this.defaultNetwork]) {
|
|
20
18
|
const network = this.config.networks[this.defaultNetwork];
|
|
21
|
-
this.logger.info(`Endpoint: ${network?.endpoint}`);
|
|
22
|
-
this.wsProvider = new ws.WsProvider(network?.endpoint);
|
|
23
19
|
this.contractAddress = network?.contract.address;
|
|
24
20
|
this.contractName = network?.contract.name;
|
|
25
21
|
this.keyring = new keyring.Keyring({
|
|
26
22
|
type: "sr25519"
|
|
27
23
|
// TODO get this from the chain
|
|
28
24
|
});
|
|
29
|
-
if (this.pair)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
if (this.pair) this.keyring.addPair(this.pair);
|
|
26
|
+
if (this.config.database) {
|
|
27
|
+
this.importDatabase().catch((err) => {
|
|
28
|
+
throw new common.ProsopoEnvError("DATABASE.DATABASE_IMPORT_FAILED", {
|
|
29
|
+
context: { error: err },
|
|
30
|
+
logger: this.logger
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
35
34
|
} else {
|
|
36
35
|
throw new common.ProsopoEnvError("CONFIG.UNKNOWN_ENVIRONMENT", {
|
|
37
|
-
context: {
|
|
36
|
+
context: {
|
|
37
|
+
constructor: this.constructor.name,
|
|
38
|
+
environment: this.config.defaultEnvironment
|
|
39
|
+
}
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -44,7 +46,6 @@ class Environment {
|
|
|
44
46
|
context: { failedFuncName: this.getSigner.name }
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
|
-
await this.getApi().isReadyOrError;
|
|
48
49
|
try {
|
|
49
50
|
this.pair = this.keyring.addPair(this.pair);
|
|
50
51
|
} catch (error) {
|
|
@@ -54,86 +55,49 @@ class Environment {
|
|
|
54
55
|
}
|
|
55
56
|
return this.pair;
|
|
56
57
|
}
|
|
57
|
-
getContractInterface() {
|
|
58
|
-
if (this.contractInterface === void 0) {
|
|
59
|
-
throw new common.ProsopoEnvError("CONTRACT.CONTRACT_UNDEFINED");
|
|
60
|
-
}
|
|
61
|
-
return this.contractInterface;
|
|
62
|
-
}
|
|
63
|
-
getApi() {
|
|
64
|
-
if (this.api === void 0) {
|
|
65
|
-
throw new common.ProsopoEnvError(new Error("api not setup! Please call isReady() first"));
|
|
66
|
-
}
|
|
67
|
-
return this.api;
|
|
68
|
-
}
|
|
69
58
|
getDb() {
|
|
70
59
|
if (this.db === void 0) {
|
|
71
|
-
throw new common.ProsopoEnvError(
|
|
60
|
+
throw new common.ProsopoEnvError(
|
|
61
|
+
new Error("db not setup! Please call isReady() first")
|
|
62
|
+
);
|
|
72
63
|
}
|
|
73
64
|
return this.db;
|
|
74
65
|
}
|
|
75
66
|
getAssetsResolver() {
|
|
76
67
|
if (this.assetsResolver === void 0) {
|
|
77
|
-
throw new common.ProsopoEnvError(
|
|
68
|
+
throw new common.ProsopoEnvError(
|
|
69
|
+
new Error("assetsResolver not setup! Please call isReady() first")
|
|
70
|
+
);
|
|
78
71
|
}
|
|
79
72
|
return this.assetsResolver;
|
|
80
73
|
}
|
|
81
74
|
getPair() {
|
|
82
75
|
if (this.pair === void 0) {
|
|
83
|
-
throw new common.ProsopoEnvError(
|
|
76
|
+
throw new common.ProsopoEnvError(
|
|
77
|
+
new Error("pair not setup! Please call isReady() first")
|
|
78
|
+
);
|
|
84
79
|
}
|
|
85
80
|
return this.pair;
|
|
86
81
|
}
|
|
87
|
-
async changeSigner(pair) {
|
|
88
|
-
await this.getApi().isReadyOrError;
|
|
89
|
-
this.pair = pair;
|
|
90
|
-
await this.getSigner();
|
|
91
|
-
this.contractInterface = await this.getContractApi();
|
|
92
|
-
}
|
|
93
|
-
async getContractApi() {
|
|
94
|
-
const nonce = this.pair ? await this.getApi().rpc.system.accountNextIndex(this.pair.address) : 0;
|
|
95
|
-
if (!address.isAddress(this.contractAddress)) {
|
|
96
|
-
throw new common.ProsopoEnvError("CONTRACT.CONTRACT_UNDEFINED");
|
|
97
|
-
}
|
|
98
|
-
this.contractInterface = new contract.ProsopoCaptchaContract(
|
|
99
|
-
this.getApi(),
|
|
100
|
-
this.abi,
|
|
101
|
-
this.contractAddress,
|
|
102
|
-
this.contractName,
|
|
103
|
-
parseInt(nonce.toString()),
|
|
104
|
-
this.pair,
|
|
105
|
-
this.config.logLevel,
|
|
106
|
-
this.config.account.address
|
|
107
|
-
// allows calling the contract from a public address only
|
|
108
|
-
);
|
|
109
|
-
return this.contractInterface;
|
|
110
|
-
}
|
|
111
82
|
async isReady() {
|
|
112
83
|
try {
|
|
113
84
|
if (this.pair && this.config.account.password && this.pair.isLocked) {
|
|
114
85
|
this.pair.unlock(this.config.account.password);
|
|
115
86
|
}
|
|
116
|
-
if (!this.api) {
|
|
117
|
-
this.api = await Api.ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
118
|
-
}
|
|
119
87
|
await this.getSigner();
|
|
120
|
-
if (address.isAddress(this.contractAddress)) {
|
|
121
|
-
this.contractInterface = await this.getContractApi();
|
|
122
|
-
} else {
|
|
123
|
-
console.warn("invalid contract address: " + this.contractAddress);
|
|
124
|
-
}
|
|
125
88
|
if (!this.db) {
|
|
126
|
-
await this.importDatabase()
|
|
127
|
-
this.logger.error(err);
|
|
128
|
-
});
|
|
89
|
+
await this.importDatabase();
|
|
129
90
|
}
|
|
130
91
|
if (this.db && this.db.connection?.readyState !== 1) {
|
|
131
|
-
this.logger.warn(
|
|
92
|
+
this.logger.warn("Database connection is not ready, reconnecting...");
|
|
132
93
|
await this.db.connect();
|
|
133
|
-
this.logger.info(
|
|
94
|
+
this.logger.info("Connected to db");
|
|
134
95
|
}
|
|
135
96
|
} catch (err) {
|
|
136
|
-
throw new common.ProsopoEnvError("GENERAL.ENVIRONMENT_NOT_READY", {
|
|
97
|
+
throw new common.ProsopoEnvError("GENERAL.ENVIRONMENT_NOT_READY", {
|
|
98
|
+
context: { error: err },
|
|
99
|
+
logger: this.logger
|
|
100
|
+
});
|
|
137
101
|
}
|
|
138
102
|
}
|
|
139
103
|
async importDatabase() {
|
package/dist/cjs/mockenv.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const provider = require("./provider.cjs");
|
|
4
3
|
const mnemonic = require("@polkadot/util-crypto/mnemonic");
|
|
4
|
+
const provider = require("./provider.cjs");
|
|
5
5
|
class MockEnvironment extends provider.ProviderEnvironment {
|
|
6
6
|
createAccountAndAddToKeyring() {
|
|
7
7
|
const mnemonic$1 = mnemonic.mnemonicGenerate();
|
package/dist/env.d.ts
CHANGED
|
@@ -1,37 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ProsopoCaptchaContract } from '@prosopo/contract';
|
|
9
|
-
import { ProsopoEnvironment } from '@prosopo/types-env';
|
|
10
|
-
import { WsProvider } from '@polkadot/rpc-provider/ws';
|
|
1
|
+
import { Keyring } from "@polkadot/keyring";
|
|
2
|
+
import type { KeyringPair } from "@polkadot/keyring/types";
|
|
3
|
+
import { type Logger } from "@prosopo/common";
|
|
4
|
+
import type { AssetsResolver, EnvironmentTypes, NetworkNames } from "@prosopo/types";
|
|
5
|
+
import type { ProsopoBasicConfigOutput } from "@prosopo/types";
|
|
6
|
+
import type { Database } from "@prosopo/types-database";
|
|
7
|
+
import type { ProsopoEnvironment } from "@prosopo/types-env";
|
|
11
8
|
export declare class Environment implements ProsopoEnvironment {
|
|
12
9
|
config: ProsopoBasicConfigOutput;
|
|
13
10
|
db: Database | undefined;
|
|
14
|
-
contractInterface: ProsopoCaptchaContract | undefined;
|
|
15
11
|
contractAddress: string;
|
|
16
12
|
defaultEnvironment: EnvironmentTypes;
|
|
17
13
|
defaultNetwork: NetworkNames;
|
|
18
14
|
contractName: string;
|
|
19
|
-
abi: ContractAbi;
|
|
20
15
|
logger: Logger;
|
|
21
16
|
assetsResolver: AssetsResolver | undefined;
|
|
22
|
-
wsProvider: WsProvider;
|
|
23
17
|
keyring: Keyring;
|
|
24
18
|
pair: KeyringPair | undefined;
|
|
25
|
-
api: ApiPromise | undefined;
|
|
26
19
|
constructor(config: ProsopoBasicConfigOutput, pair?: KeyringPair);
|
|
27
20
|
getSigner(): Promise<KeyringPair>;
|
|
28
|
-
getContractInterface(): ProsopoCaptchaContract;
|
|
29
|
-
getApi(): ApiPromise;
|
|
30
21
|
getDb(): Database;
|
|
31
22
|
getAssetsResolver(): AssetsResolver;
|
|
32
23
|
getPair(): KeyringPair;
|
|
33
|
-
changeSigner(pair: KeyringPair): Promise<void>;
|
|
34
|
-
getContractApi(): Promise<ProsopoCaptchaContract>;
|
|
35
24
|
isReady(): Promise<void>;
|
|
36
25
|
importDatabase(): Promise<void>;
|
|
37
26
|
}
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AAE1E,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,qBAAa,WAAY,YAAW,kBAAkB;IACrD,MAAM,EAAE,wBAAwB,CAAC;IACjC,EAAE,EAAE,QAAQ,GAAG,SAAS,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,cAAc,EAAE,YAAY,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;gBAElB,MAAM,EAAE,wBAAwB,EAAE,IAAI,CAAC,EAAE,WAAW;IAyC1D,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC;IAkBvC,KAAK,IAAI,QAAQ;IASjB,iBAAiB,IAAI,cAAc;IASnC,OAAO,IAAI,WAAW;IAShB,OAAO;IAuBP,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CA2BrC"}
|
package/dist/env.js
CHANGED
|
@@ -1,133 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ProsopoCaptchaContract } from '@prosopo/contract';
|
|
6
|
-
import { WsProvider } from '@polkadot/rpc-provider/ws';
|
|
7
|
-
import { ContractAbi as abiJson } from '@prosopo/captcha-contract/contract-info';
|
|
8
|
-
import { get } from '@prosopo/util';
|
|
9
|
-
import { isAddress } from '@polkadot/util-crypto/address';
|
|
1
|
+
import { Keyring } from "@polkadot/keyring";
|
|
2
|
+
import { ProsopoEnvError, getLogger } from "@prosopo/common";
|
|
3
|
+
import { Databases } from "@prosopo/database";
|
|
4
|
+
import { get } from "@prosopo/util";
|
|
10
5
|
export class Environment {
|
|
11
6
|
constructor(config, pair) {
|
|
12
7
|
this.config = config;
|
|
13
8
|
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
14
9
|
this.defaultNetwork = this.config.defaultNetwork;
|
|
15
10
|
this.pair = pair;
|
|
16
|
-
this.logger = getLogger(this.config.logLevel,
|
|
11
|
+
this.logger = getLogger(this.config.logLevel, "ProsopoEnvironment");
|
|
17
12
|
if (this.config.defaultNetwork &&
|
|
18
13
|
Object.prototype.hasOwnProperty.call(this.config.networks, this.config.defaultNetwork) &&
|
|
19
14
|
this.config.networks &&
|
|
20
15
|
this.config.networks[this.defaultNetwork]) {
|
|
21
16
|
const network = this.config.networks[this.defaultNetwork];
|
|
22
|
-
this.logger.info(`Endpoint: ${network?.endpoint}`);
|
|
23
|
-
this.wsProvider = new WsProvider(network?.endpoint);
|
|
24
17
|
this.contractAddress = network?.contract.address;
|
|
25
18
|
this.contractName = network?.contract.name;
|
|
26
19
|
this.keyring = new Keyring({
|
|
27
|
-
type:
|
|
20
|
+
type: "sr25519",
|
|
28
21
|
});
|
|
29
22
|
if (this.pair)
|
|
30
23
|
this.keyring.addPair(this.pair);
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
if (this.config.database) {
|
|
25
|
+
this.importDatabase().catch((err) => {
|
|
26
|
+
throw new ProsopoEnvError("DATABASE.DATABASE_IMPORT_FAILED", {
|
|
27
|
+
context: { error: err },
|
|
28
|
+
logger: this.logger,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
|
-
throw new ProsopoEnvError(
|
|
38
|
-
context: {
|
|
34
|
+
throw new ProsopoEnvError("CONFIG.UNKNOWN_ENVIRONMENT", {
|
|
35
|
+
context: {
|
|
36
|
+
constructor: this.constructor.name,
|
|
37
|
+
environment: this.config.defaultEnvironment,
|
|
38
|
+
},
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
async getSigner() {
|
|
43
43
|
if (!this.pair) {
|
|
44
|
-
throw new ProsopoEnvError(
|
|
44
|
+
throw new ProsopoEnvError("CONTRACT.SIGNER_UNDEFINED", {
|
|
45
45
|
context: { failedFuncName: this.getSigner.name },
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
await this.getApi().isReadyOrError;
|
|
49
48
|
try {
|
|
50
49
|
this.pair = this.keyring.addPair(this.pair);
|
|
51
50
|
}
|
|
52
51
|
catch (error) {
|
|
53
|
-
throw new ProsopoEnvError(
|
|
52
|
+
throw new ProsopoEnvError("CONTRACT.SIGNER_UNDEFINED", {
|
|
54
53
|
context: { failedFuncName: this.getSigner.name, error },
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
return this.pair;
|
|
58
57
|
}
|
|
59
|
-
getContractInterface() {
|
|
60
|
-
if (this.contractInterface === undefined) {
|
|
61
|
-
throw new ProsopoEnvError('CONTRACT.CONTRACT_UNDEFINED');
|
|
62
|
-
}
|
|
63
|
-
return this.contractInterface;
|
|
64
|
-
}
|
|
65
|
-
getApi() {
|
|
66
|
-
if (this.api === undefined) {
|
|
67
|
-
throw new ProsopoEnvError(new Error('api not setup! Please call isReady() first'));
|
|
68
|
-
}
|
|
69
|
-
return this.api;
|
|
70
|
-
}
|
|
71
58
|
getDb() {
|
|
72
59
|
if (this.db === undefined) {
|
|
73
|
-
throw new ProsopoEnvError(new Error(
|
|
60
|
+
throw new ProsopoEnvError(new Error("db not setup! Please call isReady() first"));
|
|
74
61
|
}
|
|
75
62
|
return this.db;
|
|
76
63
|
}
|
|
77
64
|
getAssetsResolver() {
|
|
78
65
|
if (this.assetsResolver === undefined) {
|
|
79
|
-
throw new ProsopoEnvError(new Error(
|
|
66
|
+
throw new ProsopoEnvError(new Error("assetsResolver not setup! Please call isReady() first"));
|
|
80
67
|
}
|
|
81
68
|
return this.assetsResolver;
|
|
82
69
|
}
|
|
83
70
|
getPair() {
|
|
84
71
|
if (this.pair === undefined) {
|
|
85
|
-
throw new ProsopoEnvError(new Error(
|
|
72
|
+
throw new ProsopoEnvError(new Error("pair not setup! Please call isReady() first"));
|
|
86
73
|
}
|
|
87
74
|
return this.pair;
|
|
88
75
|
}
|
|
89
|
-
async changeSigner(pair) {
|
|
90
|
-
await this.getApi().isReadyOrError;
|
|
91
|
-
this.pair = pair;
|
|
92
|
-
await this.getSigner();
|
|
93
|
-
this.contractInterface = await this.getContractApi();
|
|
94
|
-
}
|
|
95
|
-
async getContractApi() {
|
|
96
|
-
const nonce = this.pair ? await this.getApi().rpc.system.accountNextIndex(this.pair.address) : 0;
|
|
97
|
-
if (!isAddress(this.contractAddress)) {
|
|
98
|
-
throw new ProsopoEnvError('CONTRACT.CONTRACT_UNDEFINED');
|
|
99
|
-
}
|
|
100
|
-
this.contractInterface = new ProsopoCaptchaContract(this.getApi(), this.abi, this.contractAddress, this.contractName, parseInt(nonce.toString()), this.pair, this.config.logLevel, this.config.account.address);
|
|
101
|
-
return this.contractInterface;
|
|
102
|
-
}
|
|
103
76
|
async isReady() {
|
|
104
77
|
try {
|
|
105
78
|
if (this.pair && this.config.account.password && this.pair.isLocked) {
|
|
106
79
|
this.pair.unlock(this.config.account.password);
|
|
107
80
|
}
|
|
108
|
-
if (!this.api) {
|
|
109
|
-
this.api = await ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
110
|
-
}
|
|
111
81
|
await this.getSigner();
|
|
112
|
-
if (isAddress(this.contractAddress)) {
|
|
113
|
-
this.contractInterface = await this.getContractApi();
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
console.warn('invalid contract address: ' + this.contractAddress);
|
|
117
|
-
}
|
|
118
82
|
if (!this.db) {
|
|
119
|
-
await this.importDatabase()
|
|
120
|
-
this.logger.error(err);
|
|
121
|
-
});
|
|
83
|
+
await this.importDatabase();
|
|
122
84
|
}
|
|
123
85
|
if (this.db && this.db.connection?.readyState !== 1) {
|
|
124
|
-
this.logger.warn(
|
|
86
|
+
this.logger.warn("Database connection is not ready, reconnecting...");
|
|
125
87
|
await this.db.connect();
|
|
126
|
-
this.logger.info(
|
|
88
|
+
this.logger.info("Connected to db");
|
|
127
89
|
}
|
|
128
90
|
}
|
|
129
91
|
catch (err) {
|
|
130
|
-
throw new ProsopoEnvError(
|
|
92
|
+
throw new ProsopoEnvError("GENERAL.ENVIRONMENT_NOT_READY", {
|
|
93
|
+
context: { error: err },
|
|
94
|
+
logger: this.logger,
|
|
95
|
+
});
|
|
131
96
|
}
|
|
132
97
|
}
|
|
133
98
|
async importDatabase() {
|
|
@@ -141,7 +106,7 @@ export class Environment {
|
|
|
141
106
|
}
|
|
142
107
|
}
|
|
143
108
|
catch (error) {
|
|
144
|
-
throw new ProsopoEnvError(
|
|
109
|
+
throw new ProsopoEnvError("DATABASE.DATABASE_IMPORT_FAILED", {
|
|
145
110
|
context: {
|
|
146
111
|
error,
|
|
147
112
|
environment: this.config.database
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAe,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAS9C,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,OAAO,WAAW;IAYvB,YAAY,MAAgC,EAAE,IAAkB;QAC/D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;QACzD,I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CAAC,EAAE,GAAG,MAAM,eAAe,CAAC,MAAM,CACrC,QAAQ,CAAC,QAAQ,EACjB,QAAQ,CAAC,MAAM,EACf,IAAI,CAAC,MAAM,EACX,QAAQ,CAAC,UAAU,CACnB,CAAC;iBACF;aACD;SACD;QAAC,OAAO,KAAK,EAAE;YACf,MAAM,IAAI,eAAe,CAAC,iCAAiC,EAAE;gBAC5D,OAAO,EAAE;oBACR,KAAK;oBACL,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;wBAChC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC;4BAC9C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,IAAI;4BACrD,CAAC,CAAC,SAAS;wBACZ,CAAC,CAAC,SAAS;iBACZ;aACD,CAAC,CAAC;SACH;IACF,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./env.js";
|
|
2
|
+
export * from "./provider.js";
|
|
3
|
+
export * from "./mockenv.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./env.js";
|
|
2
|
+
export * from "./provider.js";
|
|
3
|
+
export * from "./mockenv.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/mockenv.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { BN } from
|
|
3
|
-
import { Dapp, Provider } from
|
|
4
|
-
import { ProviderEnvironment } from
|
|
2
|
+
import type { BN } from "@polkadot/util/bn";
|
|
3
|
+
import type { Dapp, Provider } from "@prosopo/types";
|
|
4
|
+
import { ProviderEnvironment } from "./provider.js";
|
|
5
5
|
export type TestAccount = {
|
|
6
6
|
mnemonic: string;
|
|
7
7
|
address: string;
|
package/dist/mockenv.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockenv.d.ts","sourceRoot":"","sources":["../src/mockenv.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"mockenv.d.ts","sourceRoot":"","sources":["../src/mockenv.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAEF,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACvD,aAAa,EAAE,QAAQ,CAAC;CACxB;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IAClD,aAAa,EAAE,IAAI,CAAC;CACpB;AAED,qBAAa,eAAgB,SAAQ,mBAAmB;IAChD,4BAA4B,IAAI,WAAW;CAMlD;AAED,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,eAAe,CAAC;IACrB,sBAAsB,EAAE,EAAE,CAAC;IAC3B,kBAAkB,EAAE,EAAE,CAAC;CACvB"}
|
package/dist/mockenv.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mnemonicGenerate } from "@polkadot/util-crypto/mnemonic";
|
|
2
|
+
import { ProviderEnvironment } from "./provider.js";
|
|
3
3
|
export class MockEnvironment extends ProviderEnvironment {
|
|
4
4
|
createAccountAndAddToKeyring() {
|
|
5
5
|
const mnemonic = mnemonicGenerate();
|
package/dist/mockenv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockenv.js","sourceRoot":"","sources":["../src/mockenv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mockenv.js","sourceRoot":"","sources":["../src/mockenv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAgBlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAgBpD,MAAM,OAAO,eAAgB,SAAQ,mBAAmB;IAChD,4BAA4B;QAClC,MAAM,QAAQ,GAAW,gBAAgB,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC5B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;IAC1D,CAAC;CACD"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ProsopoConfigOutput } from "@prosopo/types";
|
|
2
|
+
import { Environment } from "./env.js";
|
|
3
3
|
export declare class ProviderEnvironment extends Environment {
|
|
4
4
|
config: ProsopoConfigOutput;
|
|
5
5
|
}
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAc1D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,qBAAa,mBAAoB,SAAQ,WAAW;IAC3C,MAAM,EAAE,mBAAmB,CAAC;CACpC"}
|
package/dist/provider.js
CHANGED
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,OAAO,mBAAoB,SAAQ,WAAW;CAEnD"}
|
package/package.json
CHANGED
|
@@ -1,54 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"tslib": "2.6.2",
|
|
49
|
-
"typescript": "5.1.6"
|
|
50
|
-
},
|
|
51
|
-
"author": "Prosopo",
|
|
52
|
-
"license": "Apache-2.0",
|
|
53
|
-
"sideEffects": false
|
|
2
|
+
"name": "@prosopo/env",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Path env prosopo environment",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20",
|
|
9
|
+
"npm": ">=9"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"No test specified\"",
|
|
19
|
+
"clean": "tsc --build --clean",
|
|
20
|
+
"build": "tsc --build --verbose",
|
|
21
|
+
"build:cjs": "npx vite --config vite.cjs.config.ts build"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@polkadot/api": "10.13.1",
|
|
25
|
+
"@polkadot/keyring": "12.6.2",
|
|
26
|
+
"@polkadot/rpc-provider": "10.13.1",
|
|
27
|
+
"@polkadot/util": "12.6.2",
|
|
28
|
+
"@polkadot/util-crypto": "12.6.2",
|
|
29
|
+
"@prosopo/common": "2.0.1",
|
|
30
|
+
"@prosopo/contract": "2.0.1",
|
|
31
|
+
"@prosopo/database": "2.0.1",
|
|
32
|
+
"@prosopo/types": "2.0.1",
|
|
33
|
+
"@prosopo/types-database": "2.0.1",
|
|
34
|
+
"@prosopo/types-env": "2.0.1",
|
|
35
|
+
"@prosopo/util": "2.0.1"
|
|
36
|
+
},
|
|
37
|
+
"overrides": {
|
|
38
|
+
"@polkadot/keyring": "12.6.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@prosopo/config": "2.0.1",
|
|
42
|
+
"tslib": "2.6.2",
|
|
43
|
+
"typescript": "5.1.6"
|
|
44
|
+
},
|
|
45
|
+
"author": "Prosopo",
|
|
46
|
+
"license": "Apache-2.0",
|
|
47
|
+
"sideEffects": false
|
|
54
48
|
}
|
package/vite.cjs.config.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
// Copyright 2021-2024 Prosopo (UK) Ltd.
|
|
2
3
|
//
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -11,9 +12,8 @@
|
|
|
11
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
13
|
// See the License for the specific language governing permissions and
|
|
13
14
|
// limitations under the License.
|
|
14
|
-
import { ViteCommonJSConfig } from
|
|
15
|
-
import path from 'path'
|
|
15
|
+
import { ViteCommonJSConfig } from "@prosopo/config";
|
|
16
16
|
|
|
17
17
|
export default function () {
|
|
18
|
-
|
|
18
|
+
return ViteCommonJSConfig("env", path.resolve("./tsconfig.cjs.json"));
|
|
19
19
|
}
|