godprotocol 1.2.33 → 1.2.35

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 (2) hide show
  1. package/Objects/Oracle.js +41 -13
  2. package/package.json +1 -1
package/Objects/Oracle.js CHANGED
@@ -9,25 +9,26 @@ class Oracle_client {
9
9
  }
10
10
 
11
11
  add_repo = async (repo) => {
12
- this.repos.push(await this.Repos.cloth_repo(repo.repo));
12
+ let repo_ = await this.Repos.cloth_repo(repo.repo);
13
+ this.repos.push(repo_);
13
14
 
14
15
  await this.fetch({
15
16
  method: "add_repo",
16
17
  args: repo,
17
18
  });
19
+
20
+ return repo_;
18
21
  };
19
22
 
20
23
  write_local = async (path, content) => {
21
- let repo = this.repos[0];
22
- if (repo) {
23
- repo.write(path, content);
24
+ if (this.local) {
25
+ await this.local.write(path, content);
24
26
  }
25
27
  };
26
28
 
27
29
  read_local = async (path) => {
28
- let repo = this.repos[0];
29
- if (repo) {
30
- let content = await repo.read(path);
30
+ if (this.local) {
31
+ let content = await this.local.read(path);
31
32
  return content;
32
33
  }
33
34
  return null;
@@ -97,6 +98,12 @@ class Oracle_client {
97
98
  data: JSON.stringify(payload.args),
98
99
  });
99
100
 
101
+ if (resp.error === "Token expired") {
102
+ await this.set_auth_token(null);
103
+ await this.sync(this.client);
104
+ resp = await this.fetch(payload);
105
+ }
106
+
100
107
  return resp || null;
101
108
  } catch (e) {
102
109
  console.warn("fetch error:", e.message || e);
@@ -104,18 +111,34 @@ class Oracle_client {
104
111
  }
105
112
  };
106
113
 
107
- sync = async (client, Repos) => {
114
+ sync = async (client, Repos, local) => {
108
115
  this.client = client;
109
116
  if (Repos) this.Repos = new Repos();
110
117
 
118
+ if (local) this.local = await this.Repos.cloth_repo(local.repo);
119
+
120
+ await this.get_auth_token();
121
+ if (this.auth_token) {
122
+ if (local) {
123
+ this.local = await this.add_repo(local);
124
+ return;
125
+ }
126
+ }
111
127
  let auth = await this.fetch({
112
128
  method: "authenticate",
113
129
  args: {
114
130
  client: this.client,
115
131
  },
116
132
  });
133
+ if (!auth) return;
134
+ console.log("Oracle authenticated:", auth);
117
135
 
118
136
  if (auth.token) {
137
+ if (local) {
138
+ this.auth_token = auth.token;
139
+ this.local = await this.add_repo(local);
140
+ }
141
+
119
142
  await this.set_auth_token(auth.token);
120
143
  }
121
144
  };
@@ -124,23 +147,28 @@ class Oracle_client {
124
147
  let token = this.auth_token;
125
148
  if (!token) {
126
149
  token = await this.read_local(this.token_addr);
150
+ if (token && token.expired) token = null;
151
+ console.log("read token:", token);
127
152
  if (token) {
128
153
  token = JSON.parse(token);
129
154
  this.auth_token = token.token;
130
155
  this.client = token.client;
131
156
  }
132
157
  }
158
+ console.log("Oracle auth token:", this.auth_token);
133
159
  return this.auth_token;
134
160
  };
135
161
 
136
162
  token_addr = `.accounts/sign`;
137
163
 
138
164
  set_auth_token = async (token) => {
139
- this.auth_token = token;
140
- this.write_local(
141
- this.token_addr,
142
- JSON.stringify({ client: this.client, token })
143
- );
165
+ let obj = { client: this.client, token };
166
+ if (!token) {
167
+ this.auth_token = null;
168
+
169
+ obj.expired = true;
170
+ }
171
+ await this.write_local(this.token_addr, JSON.stringify(obj));
144
172
  };
145
173
 
146
174
  cloth_repo = async (repo) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.2.33",
3
+ "version": "1.2.35",
4
4
  "description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
5
5
  "main": "Index.js",
6
6
  "type": "module",