trac-peer 0.0.89 → 0.0.91

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.89",
4
+ "version": "0.0.91",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "trac-wallet": "^0.0.34",
package/src/api.js CHANGED
@@ -4,180 +4,163 @@ export class ProtocolApi{
4
4
  }
5
5
 
6
6
  async getAdmin(signed = true){
7
- const get = this.peer.protocol_instance.getSigned;
8
- if(true !== signed) this.peer.protocol_instance.get;
9
- const res = await get('admin');
10
- if(null !== res) {
11
- return res.value
12
- }
7
+ let res = null;
8
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('admin');
9
+ if(false === signed) res = await this.peer.protocol_instance.get('admin');
10
+ if(null !== res) return res;
13
11
  return null;
14
12
  }
15
13
 
16
14
  async getWhitelistEnabled(signed = true){
17
- const get = this.peer.protocol_instance.getSigned;
18
- if(true !== signed) this.peer.protocol_instance.get;
19
- const res = await get('wlst');
20
- if(null !== res) {
21
- return res.value
22
- }
15
+ let res = null;
16
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('wlst');
17
+ if(false === signed) res = await this.peer.protocol_instance.get('wlst');
18
+ if(null !== res) return res;
23
19
  return false;
24
20
  }
25
21
 
26
22
  async getWhitelistStatus(address, signed = true){
27
- const get = this.peer.protocol_instance.getSigned;
28
- if(true !== signed) this.peer.protocol_instance.get;
29
- const res = await get('wl/'+address);
30
- if(null !== res) {
31
- return res.value
32
- }
23
+ let res = null;
24
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('wl/'+address);
25
+ if(false === signed) res = await this.peer.protocol_instance.get('wl/'+address);
26
+ if(null !== res) return res;
33
27
  return false;
34
28
  }
35
29
 
36
30
  async getModStatus(address, signed = true){
37
- const get = this.peer.protocol_instance.getSigned;
38
- if(true !== signed) this.peer.protocol_instance.get;
39
- const res = await get('mod/'+address);
40
- if(null !== res) {
41
- return res.value
42
- }
31
+ let res = null;
32
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('mod/'+address);
33
+ if(false === signed) res = await this.peer.protocol_instance.get('mod/'+address);
34
+ if(null !== res) return res;
43
35
  return false;
44
36
  }
45
37
 
46
38
  async getMuteStatus(address, signed = true){
47
- const get = this.peer.protocol_instance.getSigned;
48
- if(true !== signed) this.peer.protocol_instance.get;
49
- const res = await get('mtd/'+address);
50
- if(null !== res) {
51
- return res.value
52
- }
39
+ let res = null;
40
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('mtd/'+address);
41
+ if(false === signed) res = await this.peer.protocol_instance.get('mtd/'+address);
42
+ if(null !== res) return res;
53
43
  return false;
54
44
  }
55
45
 
56
46
  async getAutoAddWritersStatus(signed = true){
57
- const get = this.peer.protocol_instance.getSigned;
58
- if(true !== signed) this.peer.protocol_instance.get;
59
- const res = await get('auto_add_writers');
47
+ let res = null;
48
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('auto_add_writers');
49
+ if(false === signed) res = await this.peer.protocol_instance.get('auto_add_writers');
60
50
  if(null !== res) {
61
- return res.value === 'on';
51
+ return res === 'on';
62
52
  }
63
53
  return false;
64
54
  }
65
55
 
66
56
  async getChatStatus(signed = true){
67
- const get = this.peer.protocol_instance.getSigned;
68
- if(true !== signed) this.peer.protocol_instance.get;
69
- const res = await get('chat_status');
57
+ let res = null;
58
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('chat_status');
59
+ if(false === signed) res = await this.peer.protocol_instance.get('chat_status');
70
60
  if(null !== res) {
71
- return res.value === 'on';
61
+ return res === 'on';
72
62
  }
73
63
  return false;
74
64
  }
75
65
 
76
66
  async getAddressFromNick(nick, signed = true){
77
- const get = this.peer.protocol_instance.getSigned;
78
- if(true !== signed) this.peer.protocol_instance.get;
79
- const res = await get('kcin/'+nick);
80
- if(null !== res) {
81
- return res.value
82
- }
83
- return null;
67
+ let res = null;
68
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('kcin/'+nick);
69
+ if(false === signed) res = await this.peer.protocol_instance.get('kcin/'+nick);
70
+ console.log(JSON.stringify(res));
71
+ return res;
84
72
  }
85
73
 
86
74
  async getNick(address, signed = true){
87
- const get = this.peer.protocol_instance.getSigned;
88
- if(true !== signed) this.peer.protocol_instance.get;
89
- const res = await get('nick/'+address);
90
- if(null !== res) {
91
- return res.value
92
- }
93
- return null;
75
+ let res = null;
76
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('nick/'+address);
77
+ if(false === signed) res = await this.peer.protocol_instance.get('nick/'+address);
78
+ console.log(JSON.stringify(res));
79
+ return res;
94
80
  }
95
81
 
96
82
  async getDeletedMessageLength(signed = true){
97
- const get = this.peer.protocol_instance.getSigned;
98
- if(true !== signed) this.peer.protocol_instance.get;
99
- const res = await get('delml');
100
- if(null !== res) {
101
- return res.value
102
- }
103
- return 0;
83
+ let res = null;
84
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('delml');
85
+ if(false === signed) res = await this.peer.protocol_instance.get('delml');
86
+ res = res !== null ? res : 0;
87
+ console.log(JSON.stringify(res));
88
+ return res;
104
89
  }
105
90
 
106
91
  async getDeletedMessage(index, signed = true){
107
- const get = this.peer.protocol_instance.getSigned;
108
- if(true !== signed) this.peer.protocol_instance.get;
109
- const res = await get('delm/'+parseInt(index));
110
- return await this.getMessage(res.value, signed);
92
+ let res = null;
93
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('delm/'+parseInt(index));
94
+ if(false === signed) res = await this.peer.protocol_instance.get('delm/'+parseInt(index));
95
+ if(null === res) {
96
+ console.log(JSON.stringify(null));
97
+ return null
98
+ }
99
+ return await this.getMessage(res, signed);
111
100
  }
112
101
 
113
102
  async getMessageLength(signed = true){
114
- const get = this.peer.protocol_instance.getSigned;
115
- if(true !== signed) this.peer.protocol_instance.get;
116
- const res = await get('msgl');
117
- if(null !== res) {
118
- return res.value
119
- }
120
- return 0;
103
+ let res = null;
104
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('msgl');
105
+ if(false === signed) res = await this.peer.protocol_instance.get('msgl');
106
+ res = res !== null ? res : 0;
107
+ console.log(JSON.stringify(res));
108
+ return res;
121
109
  }
122
110
 
123
111
  async getMessage(index, signed = true){
124
- const get = this.peer.protocol_instance.getSigned;
125
- if(true !== signed) this.peer.protocol_instance.get;
126
- const res = await get('msg/'+parseInt(index));
127
- if(null !== res) {
128
- return res.value
129
- }
130
- return null;
112
+ let res = null;
113
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('msg/'+parseInt(index));
114
+ if(false === signed) res = await this.peer.protocol_instance.get('msg/'+parseInt(index));
115
+ console.log(JSON.stringify(res));
116
+ return res;
131
117
  }
132
118
 
133
119
  async getUserMessageLength(address, signed = true){
134
- const get = this.peer.protocol_instance.getSigned;
135
- if(true !== signed) this.peer.protocol_instance.get;
136
- const res = await get('umsgl/'+address);
137
- if(null !== res) {
138
- return res.value
139
- }
140
- return 0;
120
+ let res = null;
121
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('umsgl/'+address);
122
+ if(false === signed) res = await this.peer.protocol_instance.get('umsgl/'+address);
123
+ res = res !== null ? res : 0;
124
+ console.log(JSON.stringify(res));
125
+ return res;
141
126
  }
142
127
 
143
128
  async getUserMessage(address, index, signed = true){
144
- const get = this.peer.protocol_instance.getSigned;
145
- if(true !== signed) this.peer.protocol_instance.get;
146
- const res = await get('umsg/'+address+'/'+parseInt(index));
147
- if(null === res) return null;
148
- return await this.getMessage(res.value);
129
+ let res = null;
130
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('umsg/'+address+'/'+parseInt(index));
131
+ if(false === signed) res = await this.peer.protocol_instance.get('umsg/'+address+'/'+parseInt(index));
132
+ if(null === res) {
133
+ console.log(JSON.stringify(null));
134
+ return null
135
+ }
136
+ return await this.getMessage(res, signed);
149
137
  }
150
138
 
151
139
  async getTxLength(signed = true){
152
- const get = this.peer.protocol_instance.getSigned;
153
- if(true !== signed) this.peer.protocol_instance.get;
154
- const res = await get('txl');
155
- if(null !== res) {
156
- return res.value
157
- }
158
- return 0;
140
+ let res = null;
141
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('txl');
142
+ if(false === signed) res = await this.peer.protocol_instance.get('txl');
143
+ res = res !== null ? res : 0;
144
+ console.log(JSON.stringify(res));
145
+ return res;
159
146
  }
160
147
 
161
148
  async getTx(index, signed = true){
162
- const get = this.peer.protocol_instance.getSigned;
163
- if(true !== signed) this.peer.protocol_instance.get;
164
- const res = await get('txi/'+parseInt(index));
165
- if(null !== res) {
166
- return res.value
167
- }
168
- return null;
149
+ let res = null;
150
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('txi/'+parseInt(index));
151
+ if(false === signed) res = await this.peer.protocol_instance.get('txi/'+parseInt(index));
152
+ console.log(JSON.stringify(res));
153
+ return res;
169
154
  }
170
155
 
171
156
  async getTxData(index, signed = true){
172
- const get = this.peer.protocol_instance.getSigned;
173
- if(true !== signed) this.peer.protocol_instance.get;
174
157
  const tx = await this.getTx(index, signed);
175
158
  if(null === tx) return null;
176
- const res = await get('tx/'+tx);
177
- if(null !== res) {
178
- return res.value
179
- }
180
- return null;
159
+ let res = null;
160
+ if(true === signed) res = await this.peer.protocol_instance.getSigned('tx/'+tx);
161
+ if(false === signed) res = await this.peer.protocol_instance.get('tx/'+tx);
162
+ console.log(JSON.stringify(res));
163
+ return res;
181
164
  }
182
165
  }
183
166
 
package/src/protocol.js CHANGED
@@ -3,6 +3,7 @@ import {ProtocolApi} from './api.js';
3
3
 
4
4
  class Protocol{
5
5
  constructor(options = {}) {
6
+ this.api = new ProtocolApi({ peer : options.peer });
6
7
  this.base = options.base || null;
7
8
  this.peer = options.peer || null;
8
9
  this.options = options;
@@ -13,7 +14,6 @@ class Protocol{
13
14
  this.nonce = 0;
14
15
  this.prepared_transactions_content = {};
15
16
  this.features = {};
16
- this.api = new ProtocolApi({ peer : this.peer });
17
17
  }
18
18
 
19
19
  safeBigInt(value) {