godprotocol 1.2.33 → 1.2.34
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/Objects/Oracle.js +40 -13
- 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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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,33 @@ 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
|
+
console.log("Oracle authenticated:", auth);
|
|
117
134
|
|
|
118
135
|
if (auth.token) {
|
|
136
|
+
if (local) {
|
|
137
|
+
this.auth_token = auth.token;
|
|
138
|
+
this.local = await this.add_repo(local);
|
|
139
|
+
}
|
|
140
|
+
|
|
119
141
|
await this.set_auth_token(auth.token);
|
|
120
142
|
}
|
|
121
143
|
};
|
|
@@ -124,23 +146,28 @@ class Oracle_client {
|
|
|
124
146
|
let token = this.auth_token;
|
|
125
147
|
if (!token) {
|
|
126
148
|
token = await this.read_local(this.token_addr);
|
|
149
|
+
if (token && token.expired) token = null;
|
|
150
|
+
console.log("read token:", token);
|
|
127
151
|
if (token) {
|
|
128
152
|
token = JSON.parse(token);
|
|
129
153
|
this.auth_token = token.token;
|
|
130
154
|
this.client = token.client;
|
|
131
155
|
}
|
|
132
156
|
}
|
|
157
|
+
console.log("Oracle auth token:", this.auth_token);
|
|
133
158
|
return this.auth_token;
|
|
134
159
|
};
|
|
135
160
|
|
|
136
161
|
token_addr = `.accounts/sign`;
|
|
137
162
|
|
|
138
163
|
set_auth_token = async (token) => {
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
|
|
143
|
-
|
|
164
|
+
let obj = { client: this.client, token };
|
|
165
|
+
if (!token) {
|
|
166
|
+
this.auth_token = null;
|
|
167
|
+
|
|
168
|
+
obj.expired = true;
|
|
169
|
+
}
|
|
170
|
+
await this.write_local(this.token_addr, JSON.stringify(obj));
|
|
144
171
|
};
|
|
145
172
|
|
|
146
173
|
cloth_repo = async (repo) => {
|
package/package.json
CHANGED