trac-peer 0.0.63 → 0.0.65

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-peer",
3
3
  "main": "src/index.js",
4
- "version": "0.0.63",
4
+ "version": "0.0.65",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "autobase": "7.0.45",
package/src/check.js CHANGED
@@ -3,23 +3,23 @@ import Validator from 'fastest-validator';
3
3
  class Check {
4
4
 
5
5
  constructor() {
6
- this._node = null;
7
- this._tx = null;
8
- this._post_tx = null;
9
- this._msg = null;
10
- this._feature = null;
11
- this._add_writer = null;
12
- this._key = null;
13
- this._nick = null;
14
- this._mute = null;
15
- this._delete_message = null;
16
- this._mod = null;
17
- this._whitelist_status = null;
18
- this._enable_whitelist = null;
19
6
  this.validator = new Validator();
7
+ this._node = this.compileNode();
8
+ this._tx = this.compileTx();
9
+ this._post_tx = this.compilePostTx();
10
+ this._msg = this.compileMsg();
11
+ this._feature = this.compileFeature();
12
+ this._add_writer = this.compileAddWriter();
13
+ this._key = this.compileKey();
14
+ this._nick = this.compileNick();
15
+ this._mute = this.compileMute();
16
+ this._delete_message = this.compileDeleteMessage();
17
+ this._mod = this.compileMod();
18
+ this._whitelist_status = this.compileWhitelistStatus();
19
+ this._enable_whitelist = this.compileEnableWhitelist();
20
20
  }
21
21
 
22
- async compileEnableWhitelist (){
22
+ compileEnableWhitelist (){
23
23
  const schema = {
24
24
  nonce: { type : "string", min : 1 },
25
25
  hash: { type : "string", hex : null },
@@ -36,14 +36,12 @@ class Check {
36
36
  return this.validator.compile(schema);
37
37
  }
38
38
 
39
- async enableWhitelist(op){
40
- if(this._enable_whitelist === null) {
41
- this._enable_whitelist = await this.compileEnableWhitelist();
42
- }
43
- return this._enable_whitelist(op);
39
+ enableWhitelist(op){
40
+ const res = this._enable_whitelist(op);
41
+ return res === true ? true : false;
44
42
  }
45
43
 
46
- async compileWhitelistStatus (){
44
+ compileWhitelistStatus (){
47
45
  const schema = {
48
46
  nonce: { type : "string", min : 1 },
49
47
  hash: { type : "string", hex : null },
@@ -61,14 +59,12 @@ class Check {
61
59
  return this.validator.compile(schema);
62
60
  }
63
61
 
64
- async whitelistStatus(op){
65
- if(this._whitelist_status === null) {
66
- this._whitelist_status = await this.compileWhitelistStatus();
67
- }
68
- return this._whitelist_status(op);
62
+ whitelistStatus(op){
63
+ const res = this._whitelist_status(op);
64
+ return res === true ? true : false;
69
65
  }
70
66
 
71
- async compileMod (){
67
+ compileMod (){
72
68
  const schema = {
73
69
  nonce: { type : "string", min : 1 },
74
70
  hash: { type : "string", hex : null },
@@ -86,14 +82,12 @@ class Check {
86
82
  return this.validator.compile(schema);
87
83
  }
88
84
 
89
- async mod(op){
90
- if(this._mod === null) {
91
- this._mod = await this.compileMod();
92
- }
93
- return this._mod(op);
85
+ mod(op){
86
+ const res = this._mod(op);
87
+ return res === true ? true : false;
94
88
  }
95
89
 
96
- async compileDeleteMessage (){
90
+ compileDeleteMessage (){
97
91
  const schema = {
98
92
  nonce: { type : "string", min : 1 },
99
93
  hash: { type : "string", hex : null },
@@ -111,14 +105,12 @@ class Check {
111
105
  return this.validator.compile(schema);
112
106
  }
113
107
 
114
- async deleteMessage(op){
115
- if(this._delete_message === null) {
116
- this._delete_message = await this.compileDeleteMessage();
117
- }
118
- return this._delete_message(op);
108
+ deleteMessage(op){
109
+ const res = this._delete_message(op);
110
+ return res === true ? true : false;
119
111
  }
120
112
 
121
- async compileMute (){
113
+ compileMute (){
122
114
  const schema = {
123
115
  nonce: { type : "string", min : 1 },
124
116
  hash: { type : "string", hex : null },
@@ -136,14 +128,12 @@ class Check {
136
128
  return this.validator.compile(schema);
137
129
  }
138
130
 
139
- async mute(op){
140
- if(this._mute === null) {
141
- this._mute = await this.compileMute();
142
- }
143
- return this._mute(op);
131
+ mute(op){
132
+ const res = this._mute(op);
133
+ return res === true ? true : false;
144
134
  }
145
135
 
146
- async compileNick (){
136
+ compileNick (){
147
137
  const schema = {
148
138
  nonce: { type : "string", min : 1 },
149
139
  hash: { type : "string", hex : null },
@@ -161,33 +151,29 @@ class Check {
161
151
  return this.validator.compile(schema);
162
152
  }
163
153
 
164
- async nick(op){
165
- if(this._nick === null) {
166
- this._nick = await this.compileNick();
167
- }
168
- return this._nick(op);
154
+ nick(op){
155
+ const res = this._nick(op);
156
+ return res === true ? true : false;
169
157
  }
170
158
 
171
- async compileKey() {
159
+ compileKey() {
172
160
  const schema = {
173
161
  key: { type : 'string', hex: null }
174
162
  };
175
163
  return this.validator.compile(schema);
176
164
  }
177
165
 
178
- async key(op){
179
- if(this._key === null) {
180
- this._key = await this.compileKey();
181
- }
182
- return this._key(op);
166
+ key(op){
167
+ const res = this._key(op);
168
+ return res === true ? true : false;
183
169
  }
184
170
 
185
- async setStatus(op){
171
+ setStatus(op){
186
172
  // currently same as addWriter
187
- return await this.addWriter(op);
173
+ return this.addWriter(op);
188
174
  }
189
175
 
190
- async compileAddWriter (){
176
+ compileAddWriter (){
191
177
  const schema = {
192
178
  key: { type : "string", hex : null },
193
179
  hash : { type : "string", hex : null },
@@ -204,19 +190,17 @@ class Check {
204
190
  return this.validator.compile(schema);
205
191
  }
206
192
 
207
- async addIndexer(op){
193
+ addIndexer(op){
208
194
  // currently same as addWriter
209
- return await this.addWriter(op);
195
+ return this.addWriter(op);
210
196
  }
211
197
 
212
- async addWriter(op){
213
- if(this._add_writer === null) {
214
- this._add_writer = await this.compileAddWriter();
215
- }
216
- return this._add_writer(op);
198
+ addWriter(op){
199
+ const res = this._add_writer(op);
200
+ return res === true ? true : false;
217
201
  }
218
202
 
219
- async compileFeature (){
203
+ compileFeature (){
220
204
  const schema = {
221
205
  key: { type : "string", min : 1 },
222
206
  value : {
@@ -232,14 +216,12 @@ class Check {
232
216
  return this.validator.compile(schema);
233
217
  }
234
218
 
235
- async feature(op){
236
- if(this._feature === null) {
237
- this._feature = await this.compileFeature();
238
- }
239
- return this._feature(op);
219
+ feature(op){
220
+ const res = this._feature(op);
221
+ return res === true ? true : false;
240
222
  }
241
223
 
242
- async compileMsg (){
224
+ compileMsg (){
243
225
  const schema = {
244
226
  nonce: { type : "string", min : 1 },
245
227
  hash: { type : "string", hex : null },
@@ -258,14 +240,12 @@ class Check {
258
240
  return this.validator.compile(schema);
259
241
  }
260
242
 
261
- async msg(op){
262
- if(this._msg === null) {
263
- this._msg = await this.compileMsg();
264
- }
265
- return this._msg(op);
243
+ msg(op){
244
+ const res = this._msg(op);
245
+ return res === true ? true : false;
266
246
  }
267
247
 
268
- async compilePostTx() {
248
+ compilePostTx() {
269
249
  const schema = {
270
250
  value : {
271
251
  $$type: "object",
@@ -276,14 +256,12 @@ class Check {
276
256
  return this.validator.compile(schema);
277
257
  }
278
258
 
279
- async postTx(post_tx){
280
- if(this._post_tx === null) {
281
- this._post_tx = await this.compilePostTx();
282
- }
283
- return this._post_tx(post_tx);
259
+ postTx(post_tx){
260
+ const res = this._post_tx(post_tx);
261
+ return res === true ? true : false;
284
262
  }
285
263
 
286
- async compileNode() {
264
+ compileNode() {
287
265
  const schema = {
288
266
  from : {
289
267
  $$type: "object",
@@ -297,14 +275,12 @@ class Check {
297
275
  return this.validator.compile(schema);
298
276
  }
299
277
 
300
- async node(node){
301
- if(this._node === null) {
302
- this._node = await this.compileNode();
303
- }
304
- return this._node(node);
278
+ node(node){
279
+ const res = this._node(node);
280
+ return res === true ? true : false;
305
281
  }
306
282
 
307
- async compileTx() {
283
+ compileTx() {
308
284
  const schema = {
309
285
  key: { type : "string", hex : null },
310
286
  value : {
@@ -316,11 +292,9 @@ class Check {
316
292
  return this.validator.compile(schema);
317
293
  }
318
294
 
319
- async tx(op){
320
- if(this._tx === null) {
321
- this._tx = await this.compileTx();
322
- }
323
- return this._tx(op);
295
+ tx(op){
296
+ const res = this._tx(op);
297
+ return res === true ? true : false;
324
298
  }
325
299
  }
326
300
 
package/src/contract.js CHANGED
@@ -51,15 +51,15 @@ class Contract {
51
51
  }
52
52
 
53
53
  async execute(op, node, storage){
54
- if(false === this.enter_execute_schema(op)) return;
54
+ if(true !== this.enter_execute_schema(op)) return;
55
55
 
56
56
  this.address = null;
57
57
  if(op.type !== 'feature' && op.type !== 'msg'){
58
58
  if(false === this.tx_schema(op)) return;
59
59
  this.address = op.value.value.ipk;
60
60
  } else {
61
- if(false === this.address_schema(op)) return;
62
- if(op.type === 'feature' && false === this.textkey_schema(op)) return;
61
+ if(true !== this.address_schema(op)) return;
62
+ if(op.type === 'feature' && true !== this.textkey_schema(op)) return;
63
63
  if(op.type === 'feature') this.is_feature = true;
64
64
  if(op.type === 'msg') this.is_message = true;
65
65
  this.address = op.value.dispatch.address;
package/src/index.js CHANGED
@@ -79,7 +79,7 @@ export class Peer extends ReadyResource {
79
79
  if(false === await this.check.node(node)) continue;
80
80
  const op = node.value;
81
81
  if (op.type === 'tx') {
82
- if(false === await this.check.tx(op)) continue;
82
+ if(false === this.check.tx(op)) continue;
83
83
  const str_dispatch = jsonStringify(op.value.dispatch);
84
84
  const msb_view_session = _this.msb.base.view.checkout(op.value.msbsl);
85
85
  const post_tx = await msb_view_session.get(op.key);
@@ -87,7 +87,7 @@ export class Peer extends ReadyResource {
87
87
  if(false === await this.check.postTx(post_tx)) continue;
88
88
  if (null !== str_dispatch &&
89
89
  null === await batch.get('tx/'+op.key) &&
90
- op.key === post_tx.value.tx &&
90
+ post_tx.value.tx === op.key &&
91
91
  post_tx.value.ch === createHash('sha256').update(str_dispatch).digest('hex')) {
92
92
  await batch.put('tx/'+op.key, op.value);
93
93
  await _this.contract_instance.execute(op, node, batch);
@@ -450,12 +450,13 @@ export class Peer extends ReadyResource {
450
450
  delete this.protocol_instance.prepared_transactions_content[tx];
451
451
  continue;
452
452
  }
453
- const view_session = this.msb.base.view.checkout(this.msb.base.view.core.signedLength);
453
+ const msbsl = this.msb.base.view.core.signedLength;
454
+ const view_session = this.msb.base.view.checkout(msbsl);
454
455
  const msb_tx = await view_session.get(tx);
455
456
  await view_session.close();
456
457
  if(null !== msb_tx){
457
458
  msb_tx['dispatch'] = this.protocol_instance.prepared_transactions_content[tx];
458
- msb_tx['msbsl'] = this.msb.base.view.core.signedLength;
459
+ msb_tx['msbsl'] = msbsl;
459
460
  delete this.tx_pool[tx];
460
461
  delete this.protocol_instance.prepared_transactions_content[tx];
461
462
  await this.base.append({ type: 'tx', key: tx, value: msb_tx });