genlayer 0.0.25 → 0.0.26

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/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
 
2
2
 
3
+ ## 0.0.26 (2024-05-07)
4
+
3
5
  ## 0.0.25 (2024-05-06)
4
6
 
5
7
 
package/dist/index.js CHANGED
@@ -39896,7 +39896,7 @@ var {
39896
39896
  } = import_index.default;
39897
39897
 
39898
39898
  // package.json
39899
- var version = "0.0.25";
39899
+ var version = "0.0.26";
39900
39900
 
39901
39901
  // src/lib/config/text.ts
39902
39902
  var CLI_DESCRIPTION = "GenLayer CLI is a development environment for the GenLayer ecosystem. It allows developers to interact with the protocol by creating accounts, sending transactions, and working with Intelligent Contracts by testing, debugging, and deploying them.";
@@ -44521,13 +44521,13 @@ function waitForSimulatorToBeReady() {
44521
44521
  yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
44522
44522
  return waitForSimulatorToBeReady(retries - 1);
44523
44523
  }
44524
- return { initialized: false, error: "ERROR" };
44524
+ return { initialized: false, errorCode: "ERROR", errorMessage: error.message };
44525
44525
  }
44526
- return { initialized: false, error: "TIMEOUT" };
44526
+ return { initialized: false, errorCode: "TIMEOUT" };
44527
44527
  });
44528
44528
  }
44529
- function clearDatabaseTables() {
44530
- return rpcClient.request({ method: "clear_tables", params: [] });
44529
+ function clearAccountsAndTransactionsDatabase() {
44530
+ return rpcClient.request({ method: "clear_account_and_transactions_tables", params: [] });
44531
44531
  }
44532
44532
  function initializeDatabase() {
44533
44533
  return __async(this, null, function* () {
@@ -44659,12 +44659,13 @@ function initAction(options) {
44659
44659
  return;
44660
44660
  }
44661
44661
  try {
44662
- const { initialized, error } = yield waitForSimulatorToBeReady();
44663
- if (!initialized && error === "ERROR") {
44662
+ const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
44663
+ if (!initialized && errorCode === "ERROR") {
44664
+ console.log(errorMessage);
44664
44665
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
44665
44666
  return;
44666
44667
  }
44667
- if (!initialized && error === "TIMEOUT") {
44668
+ if (!initialized && errorCode === "TIMEOUT") {
44668
44669
  console.error(
44669
44670
  "The simulator is taking too long to initialize. Please try again after the simulator is ready."
44670
44671
  );
@@ -44681,7 +44682,7 @@ function initAction(options) {
44681
44682
  }
44682
44683
  console.log("Initializing the database...");
44683
44684
  try {
44684
- yield clearDatabaseTables();
44685
+ yield clearAccountsAndTransactionsDatabase();
44685
44686
  const { createResponse, tablesResponse } = yield initializeDatabase();
44686
44687
  if (!createResponse || !tablesResponse) {
44687
44688
  console.error("Unable to initialize the database. Please try again.");
@@ -44714,8 +44715,10 @@ function initAction(options) {
44714
44715
  // src/commands/general/start.ts
44715
44716
  function startAction(options) {
44716
44717
  return __async(this, null, function* () {
44717
- const restartHintText = options.restart ? "restarting the database and validators" : "keeping the database and validators previous configuration";
44718
- console.log(`Starting GenLayer simulator ${restartHintText}`);
44718
+ const { resetAccounts, resetValidators } = options;
44719
+ const restartAccountsHintText = resetAccounts ? "restarting the accounts and transactions database" : "keeping the accounts and transactions records";
44720
+ const restartValidatorsHintText = resetValidators ? "and creating new random validators" : "and keeping the existing validators";
44721
+ console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
44719
44722
  console.log(`Updating GenLayer Simulator...`);
44720
44723
  try {
44721
44724
  yield updateSimulator();
@@ -44731,12 +44734,13 @@ function startAction(options) {
44731
44734
  return;
44732
44735
  }
44733
44736
  try {
44734
- const { initialized, error } = yield waitForSimulatorToBeReady();
44735
- if (!initialized && error === "ERROR") {
44737
+ const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
44738
+ if (!initialized && errorCode === "ERROR") {
44739
+ console.log(errorMessage);
44736
44740
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
44737
44741
  return;
44738
44742
  }
44739
- if (!initialized && error === "TIMEOUT") {
44743
+ if (!initialized && errorCode === "TIMEOUT") {
44740
44744
  console.error(
44741
44745
  "The simulator is taking too long to initialize. Please try again after the simulator is ready."
44742
44746
  );
@@ -44747,10 +44751,10 @@ function startAction(options) {
44747
44751
  console.error(error);
44748
44752
  return;
44749
44753
  }
44750
- if (options.restart) {
44754
+ if (resetAccounts) {
44751
44755
  console.log("Initializing the database...");
44752
44756
  try {
44753
- yield clearDatabaseTables();
44757
+ yield clearAccountsAndTransactionsDatabase();
44754
44758
  const { createResponse, tablesResponse } = yield initializeDatabase();
44755
44759
  if (!createResponse || !tablesResponse) {
44756
44760
  console.error("Unable to initialize the database. Please try again.");
@@ -44760,6 +44764,9 @@ function startAction(options) {
44760
44764
  console.error(error);
44761
44765
  return;
44762
44766
  }
44767
+ console.log("Database successfully reset...");
44768
+ }
44769
+ if (resetValidators) {
44763
44770
  console.log("Initializing validators...");
44764
44771
  try {
44765
44772
  yield deleteAllValidators();
@@ -44769,6 +44776,7 @@ function startAction(options) {
44769
44776
  console.error(error);
44770
44777
  return;
44771
44778
  }
44779
+ console.log("New random validators successfully created...");
44772
44780
  }
44773
44781
  console.log(
44774
44782
  `GenLayer simulator initialized successfully! Go to ${getFrontendUrl()} in your browser to access it.`
@@ -44784,7 +44792,7 @@ function startAction(options) {
44784
44792
  // src/commands/general/index.ts
44785
44793
  function initializeGeneralCommands(program2) {
44786
44794
  program2.command("init").description("Initialize the GenLayer Environment").option("-n, --numValidators <numValidators>", "Number of validators", "5").action(initAction);
44787
- program2.command("up").description("Starts GenLayer's simulator").option("-nr, --no-restart", "Don't restart the database and validators", true).action(startAction);
44795
+ program2.command("up").description("Starts GenLayer's simulator").option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true).option("--reset-validators", "Remove all current validators and create new random ones", false).action(startAction);
44788
44796
  return program2;
44789
44797
  }
44790
44798
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -13,7 +13,8 @@ export function initializeGeneralCommands(program: Command) {
13
13
  program
14
14
  .command("up")
15
15
  .description("Starts GenLayer's simulator")
16
- .option("-nr, --no-restart", "Don't restart the database and validators", true)
16
+ .option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true)
17
+ .option("--reset-validators", "Remove all current validators and create new random ones", false)
17
18
  .action(startAction);
18
19
 
19
20
  return program;
@@ -9,7 +9,7 @@ import {
9
9
  runSimulator,
10
10
  waitForSimulatorToBeReady,
11
11
  updateSimulator,
12
- clearDatabaseTables,
12
+ clearAccountsAndTransactionsDatabase,
13
13
  createRandomValidators,
14
14
  deleteAllValidators,
15
15
  pullOllamaModel,
@@ -140,12 +140,13 @@ export async function initAction(options: InitActionOptions) {
140
140
  }
141
141
 
142
142
  try {
143
- const {initialized, error} = await waitForSimulatorToBeReady();
144
- if (!initialized && error === "ERROR") {
143
+ const {initialized, errorCode, errorMessage} = await waitForSimulatorToBeReady();
144
+ if (!initialized && errorCode === "ERROR") {
145
+ console.log(errorMessage);
145
146
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
146
147
  return;
147
148
  }
148
- if (!initialized && error === "TIMEOUT") {
149
+ if (!initialized && errorCode === "TIMEOUT") {
149
150
  console.error(
150
151
  "The simulator is taking too long to initialize. Please try again after the simulator is ready.",
151
152
  );
@@ -167,7 +168,7 @@ export async function initAction(options: InitActionOptions) {
167
168
  console.log("Initializing the database...");
168
169
  try {
169
170
  //remove everything from the database
170
- await clearDatabaseTables();
171
+ await clearAccountsAndTransactionsDatabase();
171
172
 
172
173
  const {createResponse, tablesResponse} = await initializeDatabase();
173
174
  if (!createResponse || !tablesResponse) {
@@ -4,21 +4,29 @@ import {
4
4
  waitForSimulatorToBeReady,
5
5
  deleteAllValidators,
6
6
  createRandomValidators,
7
- clearDatabaseTables,
7
+ clearAccountsAndTransactionsDatabase,
8
8
  initializeDatabase,
9
9
  getFrontendUrl,
10
10
  openFrontend,
11
11
  } from "@/lib/services/simulator";
12
12
 
13
13
  export interface StartActionOptions {
14
- restart: string;
14
+ resetAccounts: string;
15
+ resetValidators: string;
15
16
  }
16
17
 
17
18
  export async function startAction(options: StartActionOptions) {
18
- const restartHintText = options.restart
19
- ? "restarting the database and validators"
20
- : "keeping the database and validators previous configuration";
21
- console.log(`Starting GenLayer simulator ${restartHintText}`);
19
+ const {resetAccounts, resetValidators} = options;
20
+
21
+ const restartAccountsHintText = resetAccounts
22
+ ? "restarting the accounts and transactions database"
23
+ : "keeping the accounts and transactions records";
24
+
25
+ const restartValidatorsHintText = resetValidators
26
+ ? "and creating new random validators"
27
+ : "and keeping the existing validators";
28
+
29
+ console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
22
30
 
23
31
  // Update the simulator to the latest version
24
32
  console.log(`Updating GenLayer Simulator...`);
@@ -39,12 +47,13 @@ export async function startAction(options: StartActionOptions) {
39
47
  }
40
48
 
41
49
  try {
42
- const {initialized, error} = await waitForSimulatorToBeReady();
43
- if (!initialized && error === "ERROR") {
50
+ const {initialized, errorCode, errorMessage} = await waitForSimulatorToBeReady();
51
+ if (!initialized && errorCode === "ERROR") {
52
+ console.log(errorMessage);
44
53
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
45
54
  return;
46
55
  }
47
- if (!initialized && error === "TIMEOUT") {
56
+ if (!initialized && errorCode === "TIMEOUT") {
48
57
  console.error(
49
58
  "The simulator is taking too long to initialize. Please try again after the simulator is ready.",
50
59
  );
@@ -56,12 +65,12 @@ export async function startAction(options: StartActionOptions) {
56
65
  return;
57
66
  }
58
67
 
59
- if (options.restart) {
68
+ if (resetAccounts) {
60
69
  // Initialize the database
61
70
  console.log("Initializing the database...");
62
71
  try {
63
72
  //remove everything from the database
64
- await clearDatabaseTables();
73
+ await clearAccountsAndTransactionsDatabase();
65
74
 
66
75
  const {createResponse, tablesResponse} = await initializeDatabase();
67
76
  if (!createResponse || !tablesResponse) {
@@ -72,7 +81,10 @@ export async function startAction(options: StartActionOptions) {
72
81
  console.error(error);
73
82
  return;
74
83
  }
84
+ console.log("Database successfully reset...");
85
+ }
75
86
 
87
+ if (resetValidators) {
76
88
  // Initializing validators
77
89
  console.log("Initializing validators...");
78
90
  try {
@@ -85,6 +97,7 @@ export async function startAction(options: StartActionOptions) {
85
97
  console.error(error);
86
98
  return;
87
99
  }
100
+ console.log("New random validators successfully created...");
88
101
  }
89
102
 
90
103
  // Simulator ready
@@ -141,7 +141,8 @@ export function runSimulator(): Promise<{stdout: string; stderr: string}> {
141
141
 
142
142
  type WaitForSimulatorToBeReadyResultType = {
143
143
  initialized: boolean;
144
- error?: "TIMEOUT" | "ERROR";
144
+ errorCode?: "TIMEOUT" | "ERROR";
145
+ errorMessage?: string;
145
146
  };
146
147
 
147
148
  export async function waitForSimulatorToBeReady(
@@ -162,14 +163,14 @@ export async function waitForSimulatorToBeReady(
162
163
  await sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
163
164
  return waitForSimulatorToBeReady(retries - 1);
164
165
  }
165
- return {initialized: false, error: "ERROR"};
166
+ return {initialized: false, errorCode: "ERROR", errorMessage: error.message};
166
167
  }
167
168
 
168
- return {initialized: false, error: "TIMEOUT"};
169
+ return {initialized: false, errorCode: "TIMEOUT"};
169
170
  }
170
171
 
171
- export function clearDatabaseTables(): Promise<any> {
172
- return rpcClient.request({method: "clear_tables", params: []});
172
+ export function clearAccountsAndTransactionsDatabase(): Promise<any> {
173
+ return rpcClient.request({method: "clear_account_and_transactions_tables", params: []});
173
174
  }
174
175
 
175
176
  type InitializeDatabaseResultType = {