trac-peer 0.0.61 → 0.0.62

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.61",
4
+ "version": "0.0.62",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "autobase": "7.1.1",
package/src/check.js CHANGED
@@ -20,12 +20,6 @@ class Check {
20
20
  }
21
21
 
22
22
  async compileEnableWhitelist (){
23
- /*
24
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.type === undefined ||
25
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
26
- op.nonce === undefined || op.value.dispatch.enabled === undefined || typeof op.value.dispatch.enabled !== 'boolean' ||
27
- op.hash === undefined) continue;
28
- */
29
23
  const schema = {
30
24
  nonce: { type : "string", min : 1 },
31
25
  hash: { type : "string", hex : null },
@@ -50,13 +44,6 @@ class Check {
50
44
  }
51
45
 
52
46
  async compileWhitelistStatus (){
53
- /*
54
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.user === undefined ||
55
- typeof op.value.dispatch.user !== "string" || op.value.dispatch.type === undefined ||
56
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
57
- op.nonce === undefined || op.value.dispatch.status === undefined || typeof op.value.dispatch.status !== 'boolean' ||
58
- op.hash === undefined) continue;
59
- */
60
47
  const schema = {
61
48
  nonce: { type : "string", min : 1 },
62
49
  hash: { type : "string", hex : null },
@@ -82,13 +69,6 @@ class Check {
82
69
  }
83
70
 
84
71
  async compileMod (){
85
- /*
86
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.user === undefined ||
87
- typeof op.value.dispatch.user !== "string" || op.value.dispatch.type === undefined ||
88
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
89
- op.nonce === undefined || op.value.dispatch.mod === undefined || typeof op.value.dispatch.mod !== 'boolean' ||
90
- op.hash === undefined) continue;
91
- */
92
72
  const schema = {
93
73
  nonce: { type : "string", min : 1 },
94
74
  hash: { type : "string", hex : null },
@@ -114,12 +94,6 @@ class Check {
114
94
  }
115
95
 
116
96
  async compileDeleteMessage (){
117
- /*
118
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.id === undefined ||
119
- typeof op.value.dispatch.id !== "number" || op.value.dispatch.type === undefined ||
120
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
121
- op.nonce === undefined || op.hash === undefined || op.value.dispatch.deleted_by === undefined) continue;
122
- */
123
97
  const schema = {
124
98
  nonce: { type : "string", min : 1 },
125
99
  hash: { type : "string", hex : null },
@@ -127,7 +101,7 @@ class Check {
127
101
  $$type: "object",
128
102
  dispatch : {
129
103
  $$type : "object",
130
- id : { type : "number", integer: true, positive: true },
104
+ id : { type : "number", integer: true, min : 0 },
131
105
  type : { type : "string", min : 1 },
132
106
  address : { type : "string", hex : null },
133
107
  deleted_by : { type : "string", hex : null, nullable : true }
@@ -145,13 +119,6 @@ class Check {
145
119
  }
146
120
 
147
121
  async compileMute (){
148
- /*
149
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.user === undefined ||
150
- typeof op.value.dispatch.user !== "string" || op.value.dispatch.type === undefined ||
151
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
152
- op.nonce === undefined || op.value.dispatch.muted === undefined || typeof op.value.dispatch.muted !== 'boolean' ||
153
- op.hash === undefined) continue;
154
- */
155
122
  const schema = {
156
123
  nonce: { type : "string", min : 1 },
157
124
  hash: { type : "string", hex : null },
@@ -177,13 +144,6 @@ class Check {
177
144
  }
178
145
 
179
146
  async compileNick (){
180
- /*
181
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.nick === undefined ||
182
- typeof op.value.dispatch.nick !== "string" || op.value.dispatch.type === undefined ||
183
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
184
- op.value.dispatch.initiator === undefined || typeof op.value.dispatch.initiator !== "string" ||
185
- op.nonce === undefined || op.hash === undefined) continue;
186
- */
187
147
  const schema = {
188
148
  nonce: { type : "string", min : 1 },
189
149
  hash: { type : "string", hex : null },
@@ -228,11 +188,6 @@ class Check {
228
188
  }
229
189
 
230
190
  async compileAddWriter (){
231
- /*
232
- if(op.key === undefined || op.value === undefined || op.hash === undefined ||
233
- op.value.msg === undefined || op.value.msg.key === undefined ||
234
- op.value.msg.type === undefined || op.nonce === undefined) continue;
235
- */
236
191
  const schema = {
237
192
  key: { type : "string", hex : null },
238
193
  hash : { type : "string", hex : null },
@@ -242,7 +197,7 @@ class Check {
242
197
  msg : {
243
198
  $$type : "object",
244
199
  type : { type : "string", min : 1 },
245
- key: { type : "string", hex : null },
200
+ key: { type : "string", hex : null }
246
201
  }
247
202
  }
248
203
  };
@@ -262,11 +217,6 @@ class Check {
262
217
  }
263
218
 
264
219
  async compileFeature (){
265
- /*
266
- if(op.key === undefined || op.value === undefined || op.value.dispatch === undefined ||
267
- op.value.dispatch.hash === undefined || op.value.dispatch.value === undefined ||
268
- op.value.dispatch.nonce === undefined) continue;
269
- */
270
220
  const schema = {
271
221
  key: { type : "string", min : 1 },
272
222
  value : {
@@ -290,13 +240,6 @@ class Check {
290
240
  }
291
241
 
292
242
  async compileMsg (){
293
- /*
294
- if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.attachments === undefined ||
295
- !Array.isArray(op.value.dispatch.attachments) || op.value.dispatch.msg === undefined ||
296
- typeof op.value.dispatch.msg !== "string" || op.value.dispatch.type === undefined ||
297
- op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
298
- op.nonce === undefined || op.hash === undefined) continue;
299
- */
300
243
  const schema = {
301
244
  nonce: { type : "string", min : 1 },
302
245
  hash: { type : "string", hex : null },
@@ -307,7 +250,8 @@ class Check {
307
250
  attachments : { type : "array", items : "string" },
308
251
  msg : { type : "string", min : 1 },
309
252
  type : { type : "string", min : 1 },
310
- address : { type : "string", hex : null }
253
+ address : { type : "string", hex : null },
254
+ deleted_by : { type : "string", hex : null, nullable : true }
311
255
  }
312
256
  }
313
257
  };
@@ -322,7 +266,6 @@ class Check {
322
266
  }
323
267
 
324
268
  async compilePostTx() {
325
- // if(op.key === undefined || op.value === undefined || op.value.dispatch === undefined) continue;
326
269
  const schema = {
327
270
  value : {
328
271
  $$type: "object",
@@ -362,13 +305,12 @@ class Check {
362
305
  }
363
306
 
364
307
  async compileTx() {
365
- // if(op.key === undefined || op.value === undefined || op.value.dispatch === undefined) continue;
366
308
  const schema = {
367
309
  key: { type : "string", hex : null },
368
310
  value : {
369
311
  $$type: "object",
370
312
  dispatch : { type : "object" },
371
- msbsl : { type : "number", integer : true, positive: true }
313
+ msbsl : { type : "number", integer : true, min : 0 }
372
314
  }
373
315
  };
374
316
  return this.validator.compile(schema);
package/src/contract.js CHANGED
@@ -13,47 +13,87 @@ class Contract {
13
13
  this.message_handler = null;
14
14
  this.root = null;
15
15
  this.validator = new Validator();
16
+
17
+ this.enter_execute_schema = this.validator.compile({
18
+ value : {
19
+ $$type: "object",
20
+ dispatch : {
21
+ $$type : "object",
22
+ type : { type : "string", min : 1 }
23
+ }
24
+ }
25
+ });
26
+
27
+ this.tx_schema = this.validator.compile({
28
+ key : { type : "string", hex : null },
29
+ value : {
30
+ $$type: "object",
31
+ value : {
32
+ $$type : "object",
33
+ ipk : { type : "string", hex : null }
34
+ }
35
+ }
36
+ });
37
+
38
+ this.address_schema = this.validator.compile({
39
+ value : {
40
+ $$type: "object",
41
+ dispatch : {
42
+ $$type : "object",
43
+ address : { type : "string", hex : null }
44
+ }
45
+ }
46
+ });
47
+
48
+ this.textkey_schema = this.validator.compile({
49
+ key : { type : "string", min : 1 }
50
+ });
16
51
  }
17
52
 
18
53
  async execute(op, node, storage){
19
- if(op.key === undefined ||
20
- op.value === undefined ||
21
- op.value.dispatch === undefined ||
22
- op.value.dispatch.type === undefined) return await this.emptyPromise();
54
+ if(false === this.enter_execute_schema(op)) return;
23
55
 
24
56
  this.address = null;
25
-
26
57
  if(op.type !== 'feature' && op.type !== 'msg'){
27
- if(op.value.value === undefined || op.value.value.ipk === undefined) return await this.emptyPromise();
58
+ if(false === this.tx_schema(op)) return;
28
59
  this.address = op.value.value.ipk;
29
60
  } else {
30
- if(op.value.dispatch.address === undefined) return this.emptyPromise();
61
+ if(false === this.address_schema(op)) return;
62
+ if(op.type === 'feature' && false === this.textkey_schema(op)) return;
31
63
  if(op.type === 'feature') this.is_feature = true;
32
64
  if(op.type === 'msg') this.is_message = true;
33
65
  this.address = op.value.dispatch.address;
34
66
  }
35
67
 
36
- this.tx = op.key;
68
+ this.tx = op.type === 'tx' ? op.key : null;
37
69
  this.op = op.value.dispatch;
38
70
  this.node = node;
39
71
  this.storage = storage;
40
72
  this.root = op;
41
73
 
42
74
  if(this.isFeature()) {
43
- if(typeof this.features[this.op.type].func === "function"){
44
- await this.features[this.op.type].func();
75
+ if(this.features[this.op.type] !== undefined){
76
+ await this.features[this.op.type]();
45
77
  }
46
78
  } else if(this.isMessage()) {
47
- if(typeof this.message_handler === "function"){
79
+ if(this.message_handler !== undefined){
48
80
  await this.message_handler();
49
81
  }
50
82
  } else {
51
- if(typeof this[this.op.type] === "function") {
52
- if(true === this.validateSchema(this.op.type, this.op)) {
53
- this[this.op.type]();
83
+ if(this[this.op.type] !== undefined) {
84
+ if(this.schemata[this.op.type] !== undefined){
85
+ if(true === this.validateSchema(this.op.type, this.op)) {
86
+ await this[this.op.type]();
87
+ }
88
+ } else {
89
+ await this[this.op.type]();
54
90
  }
55
91
  }
56
92
  }
93
+
94
+ this.address = null;
95
+ this.is_message = false;
96
+ this.is_feature = false;
57
97
  }
58
98
 
59
99
  validateSchema(type, op) {
package/src/index.js CHANGED
@@ -450,13 +450,12 @@ export class Peer extends ReadyResource {
450
450
  delete this.protocol_instance.prepared_transactions_content[tx];
451
451
  continue;
452
452
  }
453
- const msbsl = this.msb.base.view.core.signedLength;
454
- const view_session = this.msb.base.view.checkout(msbsl);
453
+ const view_session = this.msb.base.view.checkout(this.msb.base.view.core.signedLength);
455
454
  const msb_tx = await view_session.get(tx);
456
455
  await view_session.close();
457
456
  if(null !== msb_tx){
458
457
  msb_tx['dispatch'] = this.protocol_instance.prepared_transactions_content[tx];
459
- msb_tx['msbsl'] = msbsl;
458
+ msb_tx['msbsl'] = this.msb.base.view.core.signedLength;
460
459
  delete this.tx_pool[tx];
461
460
  delete this.protocol_instance.prepared_transactions_content[tx];
462
461
  await this.base.append({ type: 'tx', key: tx, value: msb_tx });