trac-peer 0.0.87 → 0.0.88

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.87",
4
+ "version": "0.0.88",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "trac-wallet": "^0.0.34",
package/src/api.js ADDED
@@ -0,0 +1,14 @@
1
+ export class ProtocolApi{
2
+ constructor(options = {}) {
3
+ this.peer = options.peer || null;
4
+ }
5
+
6
+ async getTxLength(signed = true){
7
+ if(true === signed) {
8
+ return await this.peer.protocol_instance.getSigned('txl');
9
+ }
10
+ return await this.peer.base.view.get('txl');
11
+ }
12
+ }
13
+
14
+ export default ProtocolApi;
package/src/index.js CHANGED
@@ -427,6 +427,7 @@ export class Peer extends ReadyResource {
427
427
  peer : this,
428
428
  base : this.base
429
429
  });
430
+ await this.protocol_instance.extendApi();
430
431
  this.contract_instance = new this.contract(this.protocol_instance);
431
432
  }
432
433
 
@@ -645,6 +646,7 @@ export class Peer extends ReadyResource {
645
646
  console.log('- /set_whitelist_status | Only admin. Add/remove users to/from the chat whitelist: \'/set_whitelist_status --user "<address>" --status 1\'.');
646
647
  console.log(' ');
647
648
  console.log('- System Commands:');
649
+ console.log('- /tx | Perform a contract transaction. The validator flag broadcasts the transaction to the desired validator. The command flag contains contract commands in json format: \'/tx --validator "<validator writer key>" --command "<string, content depends on the protocol>"\'');
648
650
  console.log('- /dag | check system properties such as writer key, DAG, etc.');
649
651
  console.log('- /get_keys | prints your public and private keys. Be careful and never share your private key!');
650
652
  console.log('- /exit | Exit the program');
@@ -667,7 +669,17 @@ export class Peer extends ReadyResource {
667
669
  break;
668
670
  default:
669
671
  try {
670
- if (input.startsWith('/add_indexer') || input.startsWith('/add_writer')) {
672
+ if (input.startsWith('/tx')) {
673
+ if (this.isStreaming) {
674
+ const splitted = this.parseArgs(input);
675
+ if(splitted.validator === undefined || splitted.cmmand === undefined){
676
+ throw new Error('Missing option. Please use --validator and --command flags.');
677
+ }
678
+ await this.protocol_instance.tx(splitted);
679
+ } else {
680
+ console.log('App is not streaming yet');
681
+ }
682
+ } else if (input.startsWith('/add_indexer') || input.startsWith('/add_writer')) {
671
683
  await addWriter(input, this);
672
684
  } else if (input.startsWith('/add_admin')) {
673
685
  await addAdmin(input, this);
@@ -692,7 +704,7 @@ export class Peer extends ReadyResource {
692
704
  } else if (input.startsWith('/set_whitelist_status')) {
693
705
  await setWhitelistStatus(input, this);
694
706
  } else {
695
- this.protocol_instance.execute(input);
707
+ this.protocol_instance.customCommand(input);
696
708
  }
697
709
  } catch(e) {
698
710
  console.log('Command failed:', e.message);
package/src/protocol.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { formatNumberString, resolveNumberString } from "./functions.js";
2
+ import {ProtocolApi} from './api.js';
2
3
 
3
4
  class Protocol{
4
5
  constructor(options = {}) {
@@ -12,6 +13,7 @@ class Protocol{
12
13
  this.nonce = 0;
13
14
  this.prepared_transactions_content = {};
14
15
  this.features = {};
16
+ this.api = new ProtocolApi({ peer : this.peer });
15
17
  }
16
18
 
17
19
  parseArgs(cmdline) {
@@ -103,13 +105,15 @@ class Protocol{
103
105
  }
104
106
  }
105
107
 
106
- async execute(input){
107
- throw new Error('Not implemented: Protocol.execute(input)');
108
+ async tx(subject){
109
+ throw new Error('Not implemented: Protocol.tx(subject)');
108
110
  }
109
111
 
110
- async printOptions(){
111
- throw new Error('Not implemented: Protocol.printOptions()');
112
- }
112
+ async customCommand(input){ }
113
+
114
+ async printOptions(){ }
115
+
116
+ async extendApi(){ }
113
117
 
114
118
  async getSigned(key){
115
119
  const view_session = this.peer.base.view.checkout(this.peer.base.view.core.signedLength);